benz benz - 1 year ago 114
SQL Question

Using SELECT in the WHERE clause - Eloquent Laravel

Is it possible, we do SELECT in the WHERE clause when we use Eloquent in Laravel?

If it is possible, could you give me an example?

Now, I use Laravel 5.2.

Thank you.

Answer Source

Yes off course you can use WhereHas function

$posts = Post::whereHas('comments', function ($query) {
    $query->where('content', 'like', 'foo%');

check the documentation here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download