benz benz - 1 year ago 57
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.


Yes off course you can use WhereHas function

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

check the documentation here