A
A
an5432019-03-14 09:53:26
Laravel
an543, 2019-03-14 09:53:26

How to make a selection by value from a related table in Laravel?

Greetings! There are 3 related tables table1 hasMany table2 hasMany table3, how to select table1 if table3 id=1.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NubasLol, 2019-03-14
@an543

<code lang="php">
$posts = App\Post::whereHas('comments', function ($query) {
    $query->where('id', 1);
})->get();
</code>

https://laravel.com/docs/5.8/eloquent-relationships

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question