Raw Expressions: Raw Methods

SelectRaw

$orders = DB::table('orders')
                ->selectRaw('price * ? as price_with_tax', [1.0825])
                ->get();

WhereRaw / orWhereRaw

$orders = DB::table('orders')
                ->whereRaw('price > IF(state = "TX", ?, 100)', [200])
                ->get();

HavingRaw / orHavingRaw

$orders = DB::table('orders')
                ->select('department', DB::raw('SUM(price) as total_sales'))
                ->groupBy('department')
                ->havingRaw('SUM(price) > ?', [2500])
                ->get();

OrderByRaw

$orders = DB::table('orders')
                ->orderByRaw('updated_at - created_at DESC')
                ->get();

Raw Expressions: Raw Methods — Structure map

Clickable & Draggable!

Raw Expressions: Raw Methods — Related pages: