tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.91k stars 248 forks source link

Fix inherited custom route key name detection #540

Closed bakerkretzmar closed 2 years ago

bakerkretzmar commented 2 years ago

This PR allows Ziggy to recognize custom route key names defined in traits and parent classes of the model bound into the route. Previously, we wouldn't use the custom route key name uuid for the User model in this scenario...

class Model extends \Illuminate\Database\Eloquent\Model
{
    public function getRouteKeyName(): string
    {
        return 'uuid';
    }
}

class User extends Model
{
    //
}

...because in order to determine if a given model was using a custom route key name, we were checking if the class defining getRouteKeyName() was the exact class being bound into the route. But this fails if it's defined in a custom parent class, or a trait of a parent class.

In this PR we now check that the class defining getRouteKeyName() is not Illuminate\Database\Eloquent\Model, which should cover any situation where that method is being overridden anywhere at all.

Fixes #527.