Laravel WhereHas Eloquent Example Tutorial




Laravel WhereHas Eloquent Example Tutorial

Hi Guys,

In this tutorial,I will explain you how to laravel wherehas eloquent. you will learn about laravel eloquent whereHas() with example. we show example of wherehas eloquent in laravel.

you can easily use laravel wherehas eloquent.

Here I will give you example of laravel wherehas eloquent.

Example WhereHas Eloquent

Now this example, If you need even more power, you may use the whereHas methods to put "where" conditions on your has queries.


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Country;

class PostController extends Controller


public function index()


$country = Country::whereHas('posts', function($q){

$q->where('name', '=', 'Good Info');






array:1 [

0 => array:5 [

"id" => 1

"name" => "test"

"posts_id" => 1

"created_at" => null

"updated_at" => null



It will help you..

#Laravel 7


#Laravel 6