Gabotronix
1 month ago
216
4
General

Instantiate laravel model referenced by string

Posted 1 month ago by Gabotronix

Hi everybody, I want to instantiate a laravel model given a string as reference, that is I have a string variable $model with value "User", I want to do something like:

$userInstance = new $model();

Or similar, how can I do this?

Please sign in or create an account to participate in this conversation.