Raviya Technical
Published in

Raviya Technical

Laravel Eloquent Query | Laravel Where Clause with Mysql Function Example

$data = DB::table("items")->select("items.*")
->where(DB::raw("Year(items.created_at)"),'2016')
->orderBy('items.created_at')
->get();
$data = DB::table("items")->select("items.*")
->whereRaw(DB::raw("Year(items.created_at) = '2016'"))
->orderBy('items.created_at')
->get();

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store