In laravel tutorial it's said that we can pass an array of conditions in where function. My question is when I pass an array of conditions previously made by me it doesn't work.
Here is the code in documentation:
$users = DB::table('users')->where([
['status', '=', '1'],
['subscribed', '<>', '1'],
])->get();
My code is:
$fields = collect($request->input());
if($fields->has('data')){
$fields = collect($fields->get('data'));
$conditions = collect([]);
if($fields->has('likes')){
$fieldsL = $fields->get('likes');
$conditions->push(['likes', $fieldsL]);
}
if($fields->has('title')){
$fieldsT = $fields->get('title');
$conditions->push(['title', $fieldsT]);
}
$data = DB::table('posts')->select('*')->where($conditions)-
>get();
}
My error message:
Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '[]' in 'where clause' (SQL: select * from `posts` where `[]` is null) in file D:\laravel\lara-api\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 68
PLEASE let me know if it's impossible. thanks.