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.
<?php
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');
})->get();
dd($country->toArray());
}
}
Output
array:1 [
0 => array:5 [
"id" => 1
"name" => "test"
"posts_id" => 1
"created_at" => null
"updated_at" => null
]
]
It will help you..
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial