// Using PHP DB library in Laravel framework use Illuminate\Support\Facades\DB; $results = DB::table('users') ->select(DB::raw('CONCAT(first_name, " ", last_name) as full_name')) ->get(); foreach($results as $result) { echo $result->full_name; }
// Using PHP DB library in Laravel framework use Illuminate\Support\Facades\DB; $results = DB::table('orders') ->where(DB::raw('MONTH(order_date)'), '=', '6') ->get(); foreach($results as $result) { echo $result->order_id.' '.$result->order_date; }This example uses the MONTH function to extract the month from the order_date field in the orders table, and then compares it to the value '6'. The raw method is again used to create a DB expression, which is passed to the where method as a parameter. The output of the WHERE clause is then stored in the $results variable and looped over to print the order_id and order_date fields. Package Library: Laravel framework