A
A
Anton Mashletov2017-07-18 10:05:58
css
Anton Mashletov, 2017-07-18 10:05:58

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');
}

How do I query to find all issues where Auth::user()->id OR author OR subscriber?
PS Current version excluding subscribers:
$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

2 answer(s)
A
Anton Nikonorov, 2019-01-29
@modeusweb

nicolasgallagher.com/pure-css-speech-bubbles/demo

A
Alexey Ukolov, 2017-07-18
@mashletov

You need the orWhereHas method .
https://laravel.com/docs/5.4/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question