Closed MaatwebsiteSupport closed 10 years ago
See #3269
orWhereHas() problem
Builder::macro('whereLike', function ($attributes, string $searchTerm) {
$this->where(function (Builder $query) use ($attributes, $searchTerm) {
foreach (Arr::wrap($attributes) as $attribute) {
$query->when(
str_contains($attribute, '.'),
function (Builder $query) use ($attribute, $searchTerm) {
[$relationName, $relationAttribute] = explode('.', $attribute);
$query->orWhereHas($relationName, function (Builder $query) use ($relationAttribute, $searchTerm) {
$query->where($relationAttribute, 'LIKE', "%{$searchTerm}%");
});
},
function (Builder $query) use ($attribute, $searchTerm) {
$query->orWhere($attribute, 'LIKE', "%{$searchTerm}%");
}
);
}
});
return $this;
});`
I know this issue is closed but am on laravel 7.4 and still having this issue. Please advice Thank you
I'm trying to insert orWhereHas in a where closure to create a grouped where statement. However that results in an error message. The code I'm trying to run:
This results in the following error:
I'm running Laravel 4.1.18 on PHP 5.4.12