“laravel join query sum example” Coderfunda Code Answer’s
laravel join query sum example
0
Programing Coderfunda January 25, 2022 Laravel, php No comments
$users = User::select('users*', 'analytics.*', DB::raw('SUM(analytics.revenue) As revenue'))
->leftJoin('analytics', 'analytics.user_id', '=', 'users.id')
->where('analytics.date', Carbon::today()->toDateString())
->get();
$users = User::select('users*', 'analytics.*', DB::raw('SUM(analytics.revenue) As revenue'))
->leftJoin('analytics', 'analytics.user_id', '=', 'users.id')
->where('analytics.date', Carbon::today()->toDateString())
->get();
Programing Coderfunda January 25, 2022 Laravel, php No comments
$areas = Area::select('areas.*', DB::raw('count(area_id) as connections'))
->leftJoin('object_areas', 'object_areas.area_id', '=', 'areas.id')
->groupBy('areas.id')
->get();
DB::table('users')
->join('contacts', 'users.id', '=', 'contacts.user_id')
->join('orders', 'users.id', '=', 'orders.user_id')
->select('users.id', 'contacts.phone', 'orders.price')
->get();
DB::table('users')
->join('contacts', function($join)
{
$join->on('users.id', '=', 'contacts.user_id')->orOn(...);
})
->get();
DB::table('users')
->leftJoin('posts', 'users.id', '=', 'posts.user_id')
->get();