YouTube Icon

Code Playground.

How to use Raw Expressions in Laravel 5

CFG

How to use Raw Expressions in Laravel 5

One such cool function is that we use raw laravel queries. Such expressions are inserted as strings into the application, but if you want to use raw expressions such as aggregate functions, this is really helpful. The queries can be performed using the method DB::Raw.

Let’s create a DB::Raw method in laravel 5

$users = DB::table('users')
      ->select(DB::raw('count(*) as parent_count'),
               DB::raw('sum(amount) as parent_amount'))
      ->groupBy('parent_id')
      ->get();




CFG