class - How to get Model Object using its name from a variable in Laravel 5? -
i trying information model using name sent parameter blade using ajax call.
$.get("{{ url('auditinformation')}}", {modelname: modelname,versions:versions,currentdata:currentdata[index]});
now need retrieve information using modelname model.
so when tried this:
$auditinfo=input::all(); $modelname=$auditinfo['modelname']; $values=$modelname::find(1);
i got response class 'designation' not found
but if use
$modelname=new designation(); $values=$modelname::find(1);
then shows data want.
so understand model ( class ) object.
is there way assign object $modelname using $auditinfo['modelname'] .
thanks
if want way, should use model's namespace.
for example, if 'destination' model's namespace app\destination, should use :
$auditinfo=input::all(); $appprefix = 'app'; $modelname=$appprefix . '\' . $auditinfo['modelname']; $values=$modelname::find(1);
Comments
Post a Comment