Laravel db raw where clause example

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")




2) whereRaw()

$users = \DB::table("users")

->whereRaw("DATE_FORMAT(created_at,'%d-%m-%Y') = '19-01-2018'")



As above both example, you will understand how to use it.

I hope it can help you....

January 18, 2018 | Category : PHPLaravelLaravel 5Laravel 5.5
Related Posts

Blog Search

Copyright © 2020 HDTuto.com. All rights reserved.