Comments (4)
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.
You can find a very nice way to do it here:
from laravel-tags.
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.
Yes. What is the correct way to eager load the tags?
from laravel-tags.
Related Issues (20)
- Cannont publish "tags-migration" and "tags-config" HOT 2
- Call to undefined method MorphToMany::ordered() Exception
- BadMethodCallException with message 'Call to undefined method App\Models\User::attach()' HOT 1
- Using syncTagsWithType causes unique key constraint failure randomly? HOT 2
- Errors when using multiple database connections HOT 2
- Call to a member function map() on null
- Extending a model which uses tags HOT 1
- Missing "down" method in create tag migration HOT 2
- withAnyTags doesn't filter results when using variable HOT 1
- Get tags in use and then order by name HOT 3
- Uppercase and lowercase values creates 2 different tags HOT 1
- Can't use SpatieTagsInput in a bulk action
- getPivotModelClassName(): Return value must be of type string, null returned HOT 3
- Able to create duplicate tags with Tag::create()
- Name/Slug set to null with Laravel Backpack
- JSON field type for migration erroneous HOT 1
- Missing option to disable translations of slugs HOT 1
- Problem with using custom tag model or custom Tag table name
- Docs website shows docs for v3 only HOT 2
- No tables for migrate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-tags.