Showing posts with label laravel wherehas example. Show all posts
Showing posts with label laravel wherehas example. Show all posts

Laravel WhereHas Eloquent Example

Laravel WhereHas Eloquent Example

Hi Guys,

Today,I will learn 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.

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Country;

class BlogController extends Controller
{  

  /**
   * Write code on Method
   *
   * @return response()
   */
   public function index()
   {
       $country = Country::whereHas('blogs', function($q){
                      $q->where('name', '=', 'Good Info');
                   })->get();  
       dd($country->toArray());
   }
}
Output
array:1 [
  0 => array:5 [
    "id" => 1
    "name" => "test"
    "blogs_id" => 1
    "created_at" => null
    "updated_at" => null
  ]
]

It will help you..