Whenever you want to use a variable inside the Closure scope, you need to use the "use" keyword to pass the variable into the Closure:
foreach ($user->locations as $location) {
$r = TableName::where('id', '<>', $this->id)
->where(function ($q) use ($code) { // SEE HERE
$q->where('name', $code)
->orWhere('alias', $code); })
->get();
}
if you have an array variable like - $requestParam['name'] .
you have to define it before the query statement -
$name = $requestParam['name'];
$lastRecordResult = YrModel::where('type', self::table)
->where(function ($q) use ($name) {
$q->where('name', $name)
->orWhere('alias', $name); })
->where('t_id', $requestParam['t_id'])
->where('v_id', $requestParam['v_id'])
->count();
Note: Only a member of this blog may post a comment.