In Laravel database can I use a previously made array of conditions in where function?

  laravel, mysql, rdbms

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'],

My code is:

$fields = collect($request->input());
        $fields = collect($fields->get('data'));
        $conditions = collect([]);
            $fieldsL = $fields->get('likes');
            $conditions->push(['likes', $fieldsL]);
            $fieldsT = $fields->get('title');
            $conditions->push(['title', $fieldsT]);
        $data = DB::table('posts')->select('*')->where($conditions)-


My error message:

IlluminateDatabaseQueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '[]' in 'where clause' (SQL: select * from `posts` where `[]` is null) in file D:laravellara-apivendorlaravelframeworksrcIlluminateDatabaseConnection.php on line 68

PLEASE let me know if it’s impossible.

Source: Laravel

Leave a Reply