If you need to use sql aggregate function with where clause in laravel query builder then you can do it using db raw or whereraw function of laravel eloquent. here you will learn how to use db raw with where clause.
In this small tutorial i will give two way to use sql aggregate function with where clause. there are two way : 1) DB::raw() and 2) whereRaw(). So here basically i will give you very simple example on both way, you can understand and use it well in your laravel 5 application.
First of all we will example example using DB::raw(), so let's see bellow example:
1) DB::raw()
$users = \DB::table("users")
->where(DB::raw("(DATE_FORMAT(created_at,'%d-%m-%Y'))"),'19-01-2018')
->get();
dd($users);
2) whereRaw()
$users = \DB::table("users")
->whereRaw("DATE_FORMAT(created_at,'%d-%m-%Y') = '19-01-2018'")
->get();
dd($users);
As above both example, you will understand how to use it.
I hope it can help you....
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example