Manuel Vencato
Manuel Vencato

Reputation: 73

Laravel 5.1 - Retrieving single Models using string instead of the name of the model

Sorry for title. I don't know what to write. This is my problem: If i write this is all ok:

  $obj_license = License::where('licenses.company_id',$company->id)->first();

But this throw an error:

 $license='License';
 $obj_license = $license::where('licenses.company_id',$company->id)->first();

ERROR: Class 'Butchery_license' not found

This is just an example. I really need to have the second way working. There is a solution?

Upvotes: 1

Views: 23

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

Try to use full path to a class:

$license='App\License';
$obj_license = $license::where('licenses.company_id',$company->id)->first();

Upvotes: 1

Related Questions