ResourceDetailController & ResourceUpdateController should use Resource::detailQuery when checking existence
#5076
-
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
|
We probably need to add a code example on https://github.com/laravel/nova-dusk-suite so we can avoid any regression related to this. Can you please either add a Resource (with Model, migration, factory) example here or PR the example to https://github.com/laravel/nova-dusk-suite |
Beta Was this translation helpful? Give feedback.
-
But why wouldn't you just set |
Beta Was this translation helpful? Give feedback.
-
I just experimented with this and unfortunately I need the primaryKey to still be id for certain Eloquent functions to work as expected e.g. Simplified Replication ExampleMy example above is a very specific use case and I am struggling to find a simple use case that would make sense in the real world. However, this arbitrary example below will have worked in 4.17.2 but would have been broken since 4.18.0: Model Resource class ExampleResource extends Resource {
public function fields(NovaRequest $request) {
return [
ID::make('UUID', 'uuid'),
// ...
]
}
public function detailQuery(NovaRequest $request, $query) {
$query->orWhere('uuid', $request->resourceId);
}
public static function redirectAfterCreate(NovaRequest $request, $resource)
{
return '/resources/'.static::uriKey().'/'.$resource->uuid;
}
public static function redirectAfterUpdate(NovaRequest $request, $resource)
{
return '/resources/'.static::uriKey().'/'.$resource->uuid;
}
}WorkaroundI have managed a workaround for this issue by overriding findModelQuery via a custom request class and binded it to force it to use detailQuery if the Resource implements a specific interface.. public function findModelQuery($resourceId = null)
{
$resource = $this->newResource();
if ($resource instanceof PrefersDetailQuery) {
return $resource->detailQuery($this, $this->newQueryWithoutScopes());
}
return parent::findModelQuery($resourceId);
}$this->app->bind(ResourceCreateOrAttachRequest::class, CustomResourceCreateOrAttachRequest::class);
$this->app->bind(ResourceDetailRequest::class, CustomResourceDetailRequest::class);
$this->app->bind(UpdateResourceRequest::class, CustomUpdateResourceRequest::class);
$this->app->bind(
ResourceUpdateOrUpdateAttachedRequest::class,
CustomResourceUpdateOrUpdateAttachedRequest::class,
);class ApplicationSettingResource extends Resource implements PrefersDetailQuery |
Beta Was this translation helpful? Give feedback.
-
|
I feel like we can opt to rely on Eloquent
At the moment we 100% rely on |
Beta Was this translation helpful? Give feedback.


I feel like we can opt to rely on Eloquent
getRouteKey()andgetRouteKeyName()when developer want to use slug/uuid based route key insteads of default$primaryKey. To do this we need to modify:$routeKeyredirectAfterCreate()andredirectAfterUpdate()need to be updated.routeKeyName()as "key" and returnprimaryKeyvalue to response as "props".At the moment we 100% rely on
getKey()butLaravel\Nova\Resourcedoes usesIlluminate\Http\Resources\DelegatesToResource