Reputation: 1110
How can we pass extra parameters with Laravel with function. I tried the following code but no luck.
$endpoints = MyModel::with(['myrelation' => function($q) use ($extraParams) {
foreach ($extraParams as $param)
{
$q->orWhere('ia.paramCode','like',$param.'%');
}
}])->get();
When I use this code it shows the following error
Cannot use lexical variable $extraParams as a parameter name
Thanks in advance
Upvotes: 2
Views: 1490
Reputation: 15941
This happens in PHP 7 when you pass the same variable twice (use ($extraParams)
. Simple fix is to rename (use ($extraParams)
to (use ($someThingElse)
$endpoints = MyModel::with([
'myrelation' => function($q) use ($extraParams){
foreach ($extraParams as $param) {
$q->orWhere('ia.paramCode','like',$param.'%');
}
}
])->get();
This is a Bug in PHP 7 apply quick fix.
Upvotes: 3