Fixes for ?with query when using hashed_id

This commit is contained in:
David Bomba 2023-04-27 16:36:58 +10:00
parent 9dee71bc92
commit d884537e20
3 changed files with 19 additions and 10 deletions

View File

@ -18,6 +18,7 @@ use Illuminate\Database\Eloquent\Builder;
*/ */
class ClientFilters extends QueryFilters class ClientFilters extends QueryFilters
{ {
/** /**
* Filter by name. * Filter by name.
* *

View File

@ -293,8 +293,16 @@ abstract class QueryFilters
return $this->builder; return $this->builder;
} }
public function with(string $value): Builder public function with(string $value = ''): Builder
{ {
if (strlen($value) == 0) {
return $this->builder;
}
if($this->with_property == 'id') {
$value = $this->decodePrimaryKey($value);
}
return $this->builder return $this->builder
->orWhere($this->with_property, $value) ->orWhere($this->with_property, $value)
->orderByRaw("{$this->with_property} = ? DESC", [$value]) ->orderByRaw("{$this->with_property} = ? DESC", [$value])

View File

@ -40,15 +40,15 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function boot() public function boot()
{ {
// DB::listen(function($query) { \DB::listen(function($query) {
// nlog( nlog(
// $query->sql, $query->sql,
// [ [
// 'bindings' => $query->bindings, 'bindings' => $query->bindings,
// 'time' => $query->time 'time' => $query->time
// ] ]
// ); );
// }); });
// Model::preventLazyLoading( // Model::preventLazyLoading(
// !$this->app->isProduction() // !$this->app->isProduction()