I am new to Laravel I am trying to call a function from my model but facing the following issue
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Class 'App\Http\Controllers\Role' not found
While model is already loaded by autoloader
'App\\Role' => $baseDir . '/app/Models/Role.php'
My controller has the following code
namespace App\Http\Controllers;
class RoleController extends Controller
{
public function CreateRole()
{
$owner = new Role();
$owner->name = 'owner';
$owner->display_name = 'Project Owner'; // optional
$owner->description = 'User is the owner of a given project'; // optional
$owner->save();
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'User Administrator'; // optional
$admin->description = 'User is allowed to manage and edit other users'; // optional
$admin->save();
}
}
Thanks,
Aisha Zafar
On the begining of the file try to do this:
namespace App\Http\Controllers;
use App\Role; // <-- Add this
class RoleController extends Controller
{
...