How can I write not equal in where in laravel query builder ?
I would like to query like this e.g.
select * from Table where a != '1' and a != '2' and a != '4' and a != '6' ;
$removeIdListArray = (1,2,4,6);
$removedIdList = Stack::
->where('columnA',$removeIdListArray);
//↑What should I do?
CodePudding user response:
You can use whereNotIn
and pass an array as the second parameter
$removeIdListArray = [1,2,4,6];
$removedIdList = Stack::whereNotIn('columnA', $removeIdListArray);
Reference: Database: Query Builder
CodePudding user response:
The most fluent way :
Model::query()->whereNotIn('column', $arrayOfValues);
I will recommend you always using query() method together with your models, since it will allow you to explore all of the available options for the Laravel Model class
CodePudding user response:
Simply :
->where('columnA', '!=', $removeIdListArray);
or
->whereNot('columnA', $removeIdListArray);