Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel eloquent where if a variable has value

//by this we can create filter with "And" condition when value exists

$query->when($what,function($q,$what){
  $q->where('log_event_description', 'like', '%' . $what . '%');
})->when($detail,function($q,$detail){
  $q->where('log_details', 'like', '%' . $detail . '%');
})->when($who,function($q,$who){
  $q->where('log_event_type', 'like', '%' . $who . '%');
})->when($when,function($q,$when){
  $q->where('created_at', 'like', '%' . $when . '%');
});
Comment

PREVIOUS NEXT
Code Example
Php :: get current tax page 
Php :: checking why sql query not connecting to database 
Php :: What is the method of querying from two tables with a condition in Laravel 
Php :: was loaded over https, but requested an insecure xmlhttprequest endpoint laravel 
Php :: Prevent Displaying Uncategorized Links Wordpress 
Php :: Ajouter du contenu personnalisé sous chaque article/publication WordPress 
Php :: php connect 
Php :: find common value from sub arrays 
Php :: dropdown in crud application YII 
Php :: Comment supprimer les onglets WooCommerce dans WordPress 
Php :: big database file into database php 
Php :: keep value after submit php 
Php :: how to restrict user to some pages using php 
Php :: leggere file su piu righe php 
Php :: laravel load relationship including empty values 
Php :: laravel collection chunks 
Php :: Allow mass assignment in Laravel 
Php :: Expression #1 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query laravel 
Php :: echo $path not showing composer 
Php :: Wonder Gallery WordPress plugin php code to display a gallery 
Php :: Select All Data From MySql Database Table PHP Function 
Php :: Route::any 
Php :: faire un fichier zip en php 
Php :: How can I share limits across multiple fields gravity forms? 
Php :: Random select value on array factory Laravel 
Php :: redirect from controller to named route with prams in URL 
Php :: woo show Cross-Sells 
Php :: themeHeader 
Php :: Delete Collection (Get) 
Php :: loop IlluminateSupportCollection Object ( [items:protected] = 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =