Laravel 7/6 Eloquent whereRaw Example
Here, i will show you laravel db raw where clause. step by step explain laravel whereraw example. if you want to see example of laravel whereraw date_format then you are a right place Here you will learn laravel eloquent whereraw. Follow bellow tutorial step of laravel eloquent where db raw.
I will you get to current year and month data in example.you can simply use the whereraw in example.
First of all we will example using Whereraw(), so let's see bellow example:
Example 1:
SQL Query:
"select * from `users` where YEAR(created_at) = ?"
Laravel Query:
public function index()
{
$users = User::whereRaw('YEAR(created_at) = ?', [date('Y')])->get();
dd($users);
}
Example 2:
SQL Query:
"select * from `users` where YEAR(created_at) == ? AND MONTH(created_at) == ?"
Laravel Query:
public function index()
{
$users = User::whereRaw('YEAR(created_at) == ? AND MONTH(created_at) == ?', [date('Y'),date('m')])->get();
dd($users);
}
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