A
A
ARX22018-10-11 09:12:48
Laravel
ARX2, 2018-10-11 09:12:48

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
5bbee90fa0426945775863.png
...
5bbee9a971fa3065741497.png
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

1 answer(s)
A
Alexey Ukolov, 2018-10-11
@ARX2

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 question

Ask a Question

731 491 924 answers to any question