Laravel 7/6 Eloquent whereRaw Example

10-Apr-2023

.

Admin

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...

#Laravel 7

#Laravel

#Laravel 6