Sunday, 11 April 2021

Laravel Model Class using static method on controller, but in model its doing singleton returning one instance of current class

 Question :

In PHP laravel, we have codes like

$user = User::find(1);
var_dump($user->name);

I am not concerning how to use the find method, I am concerning why laravel use a static method? Shouldn't the use of static method make the method hard to test?

Will it be better if they designed using singleton?

e.g.

$user = User::getInstance()->find(1);
var_dump($user->name);

No comments:

Post a Comment