Answer the question
In order to leave comments, you need to log in
Laravel: How to pass value to condition when grouping SQL query parameters?
Tell me how to correctly pass a value / variable to a group of conditions when grouping parameters ?
// Грубо говоря мне нужно получить такой запрос:
select id from `table` where `order_status ` = ? and (`event_id ` = ? or `event_depend1 ` = ? or `event_depend2 ` = ?)
$varName = 'value';
$ordersData = OrderEAG::select('id')
->where('order_status', $statusActive)
->where(function ($query) {
$query->orWhere('event_id', $varName)
->orWhere('event_depend1', $varName)
->orWhere('event_depend2', $varName);
})
->get();
// Undefined variable: varName
Answer the question
In order to leave comments, you need to log in
php.net/manual/en/functions.anonymous.php
Example #3 Inheriting variables from the parent scope
$varName = 'value';
$ordersData = OrderEAG::select('id')
->where('order_status', $statusActive)
->where(function ($query) use($varName) {
$query->orWhere('event_id', $varName)
->orWhere('event_depend1', $varName)
->orWhere('event_depend2', $varName);
})
->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question