Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel select raw where

 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'),
                    DB::raw("(SELECT COUNT(ac_r.id) FROM users as ac_r WHERE ac_r.ref_id=users.id AND ac_r.ref_bonus = 1) as active_referal"),
                    DB::raw("(SELECT COUNT(ac_r.id) FROM users as ac_r WHERE ac_r.ref_id=users.id AND ac_r.ref_bonus != 1) as no_active_referal"),
                    DB::raw("((SELECT COUNT(ac_r.id) FROM users as ac_r WHERE ac_r.ref_id=users.id AND ac_r.ref_bonus = 1) * ".User::REFERAL_BONUS.") as total_money_referal"),
                ])
                ->groupBy('users.id')
   ->orderByDesc('total_referal')->paginate(100);
Comment

eloquent where raw

$query->whereRaw("(
        LOWER(name)             like '%". strtolower($search) ."%' OR
        LOWER(sku)              like '%". strtolower($search) ."%' OR
        LOWER(codigo)           like '%". strtolower($search) ."%' OR
        LOWER(descricao_curta)  like '%". strtolower($search) ."%'
    )");
Comment

eloquent where raw

/*
whereRaw / orWhereRaw
The whereRaw and orWhereRaw methods can 
be used to inject a raw "where" clause into your query. 
These methods accept an optional array of bindings as their second argument:
*/
$orders = DB::table('orders')
                ->whereRaw('price > IF(state = "TX", ?, 100)', [200])
                ->get();
Comment

PREVIOUS NEXT
Code Example
Php :: php cookies 
Php :: route laravel Target class [AuthController] does not exist 
Php :: using php to add numbers in html form 
Php :: php artisan tinker encryption cmd 
Php :: replace string in php 
Php :: insert batch in laravel 
Php :: gettype() function in PHP 
Php :: wp php category page count products 
Php :: storepublicly laravel 
Php :: Root composer.json requires php ^7.1.3 but your php version (8.0.3) does not satisfy that requirement. 
Php :: remove the last character from a string in php 
Php :: php move element to beginning of array 
Php :: start php file 
Php :: setcookie in php 
Php :: php check if string is integer 
Php :: php add custom button in wordpress editor 
Php :: The uploaded file exceeds the upload_max_filesize directive in php.ini. 
Php :: IlluminateContractsAuthAuthenticatable, AppModelsUser given, called in 
Php :: Creating Laravel and Vue Project 
Php :: laravel fontawesome blade directive 
Php :: enum in migration laravel 
Php :: Remove prefix on category title 
Php :: php pdo setting error modes 
Php :: php slice array in half 
Php :: Hide Categories - Woocommerce Product Page 
Php :: laravel request validation rules for create and update 
Php :: ajax search request 
Php :: laravel filesystem link 
Php :: laravel santum 
Php :: nested with laravel 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =