Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel when condition

$invisiblePosts = $request->query('invisible');

Article::query()
            ->when($invisiblePosts , function ($query){
                return $query->where('invisible' , true);
            },function ($query){
                return $query->where('invisible' , false);
            })
            ->get();
Comment

laravel where condition with if

$query = DB::table('user_ads')
            ->join('ads', 'users_ads.ad_id', '=', 'ads.id')
            ->orderBy($column, $method);

if ($input['search']) {
    $query->where('short_description', $input['search']);
}

if ($input['category']) {
    $query->where('category', $input['category']);
}

$query->join('users', 'users_ads.user_id', '=', 'users.id')
    ->select('ads.id', 'ads.img1', 'ads.short_description', 'ads.category', 'ads.product', 'ads.price', 'users.city')

$result= $query->get();

return $result;
Comment

PREVIOUS NEXT
Code Example
Php :: php var_dump more readable 
Php :: eloquent get trashed record 
Php :: laravel loop index 
Php :: php insert array into mysql table 
Php :: root composer.json requires php ^7.3 but your php version (8.0.3) does not satisfy that requirement. 
Php :: php filter non utf-8 characters 
Php :: php numbers 
Php :: laravel merge two query builder 
Php :: wordpress admin url 
Php :: why session is not working in laravel 
Php :: Eloquent models events 
Php :: loop in loop wordpress 
Php :: wp php go back 
Php :: create migration with model laravel 
Php :: array php 
Php :: laravel realation with has 
Php :: wpml get site url 
Php :: laravel @disabled in laravel-9 
Php :: POP UP WITH PHP 
Php :: symfony add field to entity 
Php :: null value in php 
Php :: showing from to in larvel pagination 
Php :: php unique associative array by value 
Php :: install php 7.1 on ubuntu 18.04 
Php :: laravel start que listener 
Php :: laravel upload file to aws s3 
Php :: unset php return array 
Php :: codeigniter 3 or where in 
Php :: laravel file custom name 
Php :: get cookie in laravel 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =