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 get biggest id 
Php :: laravel pdf export 
Php :: update laravel 7 to 8 
Php :: acosh php 
Php :: drop foreign key laravel eloquent 
Php :: laravel migration column types 
Php :: laravel pagination with search filter 
Php :: get_the_terms 
Php :: laravel check if collection has value 
Php :: custom fields wordpress 
Php :: Laravel route not calling function of controller 
Php :: php get last day of month 
Php :: laravel import xml to database 
Php :: php convert string to array 
Php :: laravel 8 resource 
Php :: the requested url was not found on this server. apache/2.4.46 (win64) openssl/1.1.1h php/8.0.1 server at localhost port 80 
Php :: laravel mailable from 
Php :: sanctum laravel 
Php :: do_shortcode not working 
Php :: laravel one to many relationship example 
Php :: compare two datetime php 
Php :: curl download progress bar php 
Php :: yii2 sendemail extension 
Php :: change aspect ratio of image php 
Php :: php convert float 
Php :: Drupal 9 entity.repository load entity by UUID 
Php :: PHP Parses a time string according to a specified format 
Php :: order by pre get posts 
Php :: php simple sse 
Php :: php sec to hours/minuts 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =