Giter Club home page Giter Club logo

Comments (4)

ferrarafer avatar ferrarafer commented on May 21, 2024 17

Hi, i apologize to write in a closed issue but i have a doubt about what i read here.

I use this to get all tags attached to a model
$tags = App\Models\ModelName::find(model_id)->tags

Also if i want to get all models with their tags with "Eager Loading" i do this
$models = App\Models\ModelName::with('tags')->get()

  • Why do you not suggets one of this ways, that seems simpler than the other ones?

  • Is there a reason to not use it like i do?

By the way, why is not in the documentation of the package this info? i see it usefull.

Thanks for this great package.

Kind regards,
Fernando.

from laravel-tags.

techguydev avatar techguydev commented on May 21, 2024 3

You can find a very nice way to do it here:

#80

from laravel-tags.

freekmurze avatar freekmurze commented on May 21, 2024 1

You could do this:

$tagIds = \DB::table('taggables')
   ->distinct()
   ->select('tag_id')
   ->where('taggable_type', YourModel::class)
   ->get()
   ->pluck('tag_id');

$tags = Spatie\Tags\Tag::whereIn('id', $tagIds)->get();

from laravel-tags.

ronald2wing avatar ronald2wing commented on May 21, 2024

Yes. What is the correct way to eager load the tags?

from laravel-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.