Laravel whereRaw Query Example

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)', [200])
                ->get();

The 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();

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *