Search code examples
laravelauthorizationentrust

Laravel save() not working on new object


I'm trying to use the code provided by the documentation of entrust in a controller but save() method wont execute and gives me the error

Method [save] does not exist on [App\Http\Controllers\role]

Here is the code:

$cityadmin = new Role();
$cityadmin->name= 'cityadmin';
$cityadmin->save();

Solution

  • Use full namespace:

    $cityadmin = new \App\Role;
    

    Or add this to the top of the controller:

    use App\Role;