Basically what I need to do is:
$x = 'Admin';
$model = new \ReflectionClass($x);
$model->getFieldList();
Where I have Admin model inside app folder. Obviously, this doesn't work. Does anyone have any idea? Can it be done?
you can do this, but you need to use the fully qualified class name.for example My models are in the Model
directory :
$model = 'App\Model\User';
$user=$model::where('id', $id)->first();
Firstly you need to add the namespace to your model. By default this is App\
. So your string would have to be "\App\Admin"
. Now you can simply create a class instance using this string.
$x = '\\App\\Admin';
$model = new $x();