I am trying to call a Model dynamically, but I am getting ..
Class 'xxx' not found
Here's my code:
use App\xxx;
.
.
.
$model = ucfirst(explode('_', $title)[0]);
$model::where('name', 'john')->get()->toArray();
dd($model) gives:
"xxx"
If $xxx
is not full class name, do this:
$model = 'App\\' . $model;
$model::where('name', 'john')->get()->toArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With