-
Notifications
You must be signed in to change notification settings - Fork 225
Object of class Illuminate\\Database\\Query\\Expression could not be converted to string #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you provide a test repository that recreates this issue, or write a failing test in a PR that recreates this issue? |
This is my controller, if ($request->input('search_type')) $this->search_type = Str::snake($request->search_type);
if ($request->input('per_page')) $this->per_page = $request->per_page;
if ($request->input('sort_by')) $this->sort_by = Str::snake($request->sort_by);
if ($request->input('sort_key')) $this->sort_key = ($request->sort_key == 'asc') ? 'asc' : 'desc';
if ($request->input('search')) {
$search = Str::lower(str_replace(' ', '%', $request->input('search')));
if (Str::contains($this->search_type, '.')) {
$keys = explode('.', $this->search_type);
foreach ($keys as $value) {
$key[] = Str::camel($value);
}
$searchKey = end($key);
array_pop($key);
$relation = implode('.', $key);
$data->whereHas($relation, function ($q) use ($search, $searchKey) {
$table = $q->getModel()->getTable();
$q->where($table . '.' . Str::snake($searchKey), 'like', '%' . $search . '%');
});
} else {
$searchType = Str::of($this->search_type)->camel()->toString();
if (isset($this->mapRelation[$searchType])) {
$search_type = $this->mapRelation[$searchType];
} else {
$search_type = $this->search_type;
}
$case = is_numeric($search) ? $search_type : "LOWER(" . $search_type . ")";
$data->whereRaw($case . " like '%" . $search . "%'");
}
} its work before on laravel 9.53 an this version 0.12.5 but when i try to upgrade to Laravel 10 & need upgrade laravel-model-caching to latest version, its throw an error Object of class Illuminate\Database\Query\Expression could not be converted to string so i'm revert back to laravel 9.53 and 0.125 |
its same to $data->whereHas('user', function ($q) use ($search, $searchKey) {
$table = $q->getModel()->getTable();
$q->where('users.name', 'like', '%boo yaaa%');
}); or $data->whereHas('other.relation', function ($q) use ($search, $searchKey) {
$table = $q->getModel()->getTable();
$q->where('relation.field, 'like', '%boo yaaa%');
}); |
i Found the issue , its on getColumnClauses protected function getColumnClauses(array $where) : string
{
if ($where["type"] !== "Column") {
return "";
}
return "-{$where["boolean"]}_{$where["first"]}_{$where["operator"]}_{$where["second"]}";
} i try to dump $where variable and got array:5 [ // vendor/genealabs/laravel-model-caching/src/CacheKey.php:85
"type" => "Column"
"first" => Illuminate\Database\Query\Expression {#2342
#value: ""subscriptions"."subscriber_id""
}
"operator" => "="
"second" => "users.id"
"boolean" => "and"
] in my case $where["first"] return Illuminate\Database\Query\Expression so i try overide that variable into $where["first"] = $where["first"]->getValue(\DB::connection()->getQueryGrammar()); and its works may i send pull request @mikebronner ? |
i had send PR on #442 |
Fix at #442 |
Describe the bug
A clear and concise description of what the bug is.
Eloquent Query
Please provide the complete eloquent query that caused the bug, for example:
Stack Trace
Environment
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: