Giter Site home page Giter Site logo

Comments (6)

brunogaspar avatar brunogaspar commented on June 30, 2024

What Laravel version?

from tags.

brunogaspar avatar brunogaspar commented on June 30, 2024

Can't reproduce on Laravel v5.1.21.

from tags.

tjb328 avatar tjb328 commented on June 30, 2024

Laravel 5.1.21
tags: 2.0.2

from tags.

brunogaspar avatar brunogaspar commented on June 30, 2024

@rutger1413 I can't really reproduce any issue so i assume you're doing some wrong on your end, as you can see below, both snippets returns the expected response, considering i only have one product on the database.

Either you changed your models namespaces or you have something else going on your end that you'll need to debug.

Using allTags method
var_dump(App\Product::allTags()->lists('name'));
Response
object(Illuminate\Database\Eloquent\Collection)[140]
  protected 'items' => 
    array (size=3)
      0 => string 'foo' (length=3)
      1 => string 'bar' (length=3)
      2 => string 'baz' (length=3)
Using a model entity
var_dump(App\Product::find(1)->tags->lists('name'));
Response
object(Illuminate\Database\Eloquent\Collection)[139]
  protected 'items' => 
    array (size=3)
      0 => string 'foo' (length=3)
      1 => string 'bar' (length=3)
      2 => string 'baz' (length=3)

from tags.

tjb328 avatar tjb328 commented on June 30, 2024

Ok I see what the issue is.

Model::allTags()

returns a QueryBuilder object.

Model::allTags()->get()

Returns the collection which is what I would have expected. The documentation isn't clear about this. I didn't var dump the result which is something I should have done.

By doing ->lists('name') the QueryBuilder object is now a collection. It would be good to point this out or to change allTags() to include the ->get() like so:

    /**
     * {@inheritDoc}
     */
    public static function allTags()
    {
        $instance = new static;

        //return DB::table('tags')->where('namespace', $instance->getEntityClassName())->where('count','>','0')->get();
        return $instance->createTagsModel()->whereNamespace(
            $instance->getEntityClassName()
        )->get();
    }

from tags.

brunogaspar avatar brunogaspar commented on June 30, 2024

You can submit a PR to the documentation if you want.

from tags.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.