0

This is my current query:

$logs = LogModel::where('spider_name', '=', $spider_name )->get();

How can I add two other where conditions?

2 Answers 2

2

You can chain as many conditions as you like this way:

$logs = LogModel::where('spider_name', '=', $spider_name )
                ->where('column1', '=', $value1 )
                ->where('column2', '=', $value2 )
                ->get();

When chaining conditions this way the query will be generated using the AND operator. If you need to use other operators such as OR you can read more in the Advanced Wheres section from the Laravel Query Builder Docs.

Sign up to request clarification or add additional context in comments.

Comments

0

You can chain your where calls, or just pass an array to where:

$logs = LogModel::where([
    'spider_name' => $spider_name,
    'hobit_name'  => $hobit_name,
])->get();

If you have some variables that exactly match the column names, you can use compact:

$spider_name = 'Shelob';
$hobit_name = 'Frodo';

$logs = LogModel::where(compact('spider_name', 'hobit_name'))->get();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.