cesargb / laravel-magiclink

Create link for authenticate in Laravel without password or get private content
MIT License
367 stars 43 forks source link

Custom `getConnectionName` not called on extended `MagicLink` model due to usage of `self` instead of `static` #72

Closed savander closed 2 years ago

savander commented 2 years ago

The latest change to the library broke my code: https://github.com/cesargb/laravel-magiclink/blob/82c82f92de7c64dbfc51f4a6846844ebbae45231/src/MagicLink.php#L93

I have extended your model class and done some modifications, such as overriding \Illuminate\Database\Eloquent\Model::getConnectionName to my custom one. The self keyword, do break the code, since it refers to the same class in which the new keyword is actually written. In that case, my getConnectionName is ignored and is not called.

The solution would be to use static since it uses late static binding, which refers to the class you called the method on. It should not break your code, but enable it for further modification/extension.

Is there any reason to do that? Why would you restrict modification of your code?

In this case, other methods will also be affected, for example: https://github.com/cesargb/laravel-magiclink/blob/82c82f92de7c64dbfc51f4a6846844ebbae45231/src/MagicLink.php#L165-L177

cesargb commented 2 years ago

Please, feel free to submit a PR