Answers for "laravel query count raw"

PHP
3

laravel join

$users = DB::table('users')
            ->join('contacts', 'users.id', '=', 'contacts.user_id')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->select('users.*', 'contacts.phone', 'orders.price')
            ->get();
Posted by: Guest on April-29-2020
0

laravel query count raw

DB::table('users')
	->select('users.*', DB::raw('count(orders.user_id) as count_by_user_id'))
	->join('orders' ,function($join){
		$join->on('orders.user_id', '=', 'users.id');
	})
	->groupBy('users.id')
	->orderBy('users.id', "DESC")
	->get();
Posted by: Guest on April-30-2021

Browse Popular Code Answers by Language