Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel model db raw count

$rating = User::query()
        ->join('championship_sessions', 'users.id', '=', 'championship_sessions.user_id')
        ->whereBetween('championship_sessions.created_at', [
           $activeChampionship['data']['start_time'],
           $activeChampionship['data']['end_time'],
        ])
        ->where('championship_sessions.status', '=', 1)
        ->groupBy('users.id')
        ->orderBy('users.rating', 'desc')
        ->select(['users.id', 'users.name', DB::raw('COUNT(championship_sessions.status) as rating'), 'users.status_name', 'users.status_id'])
        ->paginate(100)->toArray();
Comment

laravel db raw count where

 $users= User::query()
                ->where('users.ban', '!=', 1)
                ->where('users.rights', '=', 1)
                ->leftJoin('users as referal', 'users.id', '=', 'referal.ref_id')
                ->whereNotNull('referal.id')
                ->select([
                    'users.id',
                    'users.name',
                    'users.telegram_id',
                    DB::raw('count(referal.id) as total_referal'),
                ])
                ->groupBy('users.id')
    ->orderByDesc('total_referal')->paginate(100);
Comment

PREVIOUS NEXT
Code Example
Php :: laravel query builder join 
Php :: for i php 
Php :: laravel carbon first day of month 
Php :: php number to month 
Php :: cascade laravel 
Php :: php write file 
Php :: header location in php 
Php :: codeigniter count rows 
Php :: turn text file to string php 
Php :: php mb_convert_case 
Php :: required field in laravel admin 
Php :: readline php 
Php :: Carbon Format date with timezone in views Laravel 
Php :: how to remove public from url in laravel 8 
Php :: google fonts change font in echo php 
Php :: select tag in laravel collective 
Php :: laravel get next record 
Php :: laravel join with multiple conditions 
Php :: add new column in existing table in laravel migration 
Php :: php is scan dir recursive? 
Php :: tolower php 
Php :: woocommerce get user id by email 
Php :: convert text to slug php 
Php :: Laravel Validation check array size min and max 
Php :: laravel maintenance mode 
Php :: get key of value array php 
Php :: laravel array remove key 
Php :: Laravel seed timestamps columns 
Php :: how to pass variable in inside function into where in laravel 
Php :: PHP strtoupper() Function 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =