简体   繁体   中英

Laravel Nova: Change RouteKeyName to UUID

Is there a way to change the default RouteKey Name from ID to an UUID within Laravel Nova?

On my default Model, this is already changed but I would like to also change it within the Laravel Nova Backend.

public function getRouteKeyName()
{
 return 'uuid';
}

As far as I can tell, the answer to this is No .

That said, the Laravel Nova framework could certainly be extended to support this functionality.

The code for this is part of the InteractsWithResources concern, where there's a findModelKey method, which uses a whereKey method, which pairs against the primary key, rather than the route key.

I'm sure that we could petition the Laravel framework to add a whereRouteKey to Eloquent query builders, and then suggest the Nova framework to use the new whereRouteKey instead of the whereKey method.

Short of this, the only other alternative is to rebind the Nova Request with one of your own design, which has a high level of effort, and frankly isn't best practice.

With all of this in mind, I would sort of expect this functionality out of the box with Nova, and I would consider it to be a bug if Nova violated this (as that's the whole point of route-model binding).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM