Laravel/sql: Where Column Equals Not And Null
LARAVEL 5.4 (but probably it's a more general SQL question) Hello! I have a table with a structure: Suppose it's my model 'Table'. I want a query which: uses (receives) variables
Solution 1:
Probably you end with something like this:
if ($status_not_bad) {
$nStatus = 'bad';
} else {
$nStatus = 'good';
}
Table::thisquery()->where('status', '<>', $nStatus)
->whereNotNull('status')
->where($id[0], $id[1], $id[2])
->get();
But it would be a good idea to check $id keys first.
Solution 2:
Since row id = 3 you need <= in your where statement to have that row included in the result set
$id = ['id', '<=', 3];Solution 3:
So, I this works:
$chain = Sample::when($status_not_bad, function($query){
return$query->where('status', '<>', 'bad')
->orwhereNull('status');
})
->where([$id])
->get();
Post a Comment for "Laravel/sql: Where Column Equals Not And Null"