Answer the question
In order to leave comments, you need to log in
How to pass value from method to model?
Good afternoon. I pass some value to the method, let's say "$slug"
And when calling the model, when linking this model with another model, I need to specify where this $slug
...
Help how can this be done? If there is an alternative approach, then it will also work.
Answer the question
In order to leave comments, you need to log in
There is a very alternative approach. One might even say secret. It's called reading the documentation .
Sometimes you may wish to eager load a relationship, but also specify additional query constraints for the eager loading query. Here's an example:
$users = App\User::with(['posts' => function ($query) { $query->where('title', 'like', '%first%'); }])->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question