Laravel whereRaw query example; Through this tutorial, i am going to show you what is whereRaw in laravel and how to use whereRaw query in laravel apps.
Example 1 – Laravel whereRaw Query
$orders = DB::table('orders') ->whereRaw('price > IF(state = "TX", ?, 100)', ) ->get();
whereRaw methods can be used to inject a raw “where” clause into your query.
Example 2 – Laravel whereRaw Query
$users = User::whereRaw('YEAR(created_at) = ?', [date('Y')])->get();