Answers for "laravel eloquent where if a variable has value"

PHP
0

check if column has value in laravel eloquent

->where(function ($query) {
  $query->whereNull('exam_ends_at')
    ->orWhere('exam_ends_at', '>', Carbon::now());
})
Posted by: Guest on November-12-2020
0

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 . '%');
});
Posted by: Guest on April-07-2022

Code answers related to "laravel eloquent where if a variable has value"

Browse Popular Code Answers by Language