Answer the question
In order to leave comments, you need to log in
How to do a search on the field of the main model OR in the hasMany model?
There is a model Task(id, author_id)
There is a model Subscriber (id, task_id, user_id)
Accordingly, a Task may or may not have several Subscribers.
public function subscribers()
{
return $this->hasMany('\App\Models\Subscriber', 'task_id');
}
$tasks = Task::filter($filter)
->with('author', 'subscribers')
->where('author_id', Auth::user()->id)
->orderBy('status')
->orderBy('level', 'desc')
->orderBy('created_at', 'desc')
->get();
Answer the question
In order to leave comments, you need to log in
You need the orWhereHas method .
https://laravel.com/docs/5.4/eloquent-relationship...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question