Skip to content
Advertisement

Laravel class ‘UserRole’ not found

Hi i am trying to use a model for a test but i get Class ‘AppUserRole’ not found this is my controller where i am calling it

<?php

namespace AppHttpControllers;

use AppUserRole;
use IlluminateHttpRequest;

class TestController extends Controller
{
    public function index()
    {
        $role = UserRole::get();
        die(var_dump($role));
    }
}

and this is my model

<?php

use IlluminateDatabaseEloquentModel as Eloquent;

class UserRole extends Eloquent
{
    public $table = 'role';
    public $primaryKey = 'id_role';
    public $timestamps = false;

    const ADMIN = 1;
    const OPERATOR = 2;
    const CUSTOMER = 3;
}

I dont know what im missing, i tried to do the same with User model and it works perfect, also my table is created and populated.

Advertisement

Answer

Add a namespace to your model

namespace App;

Should look like this:

<?php

namespace App;

use IlluminateDatabaseEloquentModel as Eloquent;

class UserRole extends Eloquent
{
    public $table = 'role';
    public $primaryKey = 'id_role';
    public $timestamps = false;

    const ADMIN = 1;
    const OPERATOR = 2;
    const CUSTOMER = 3;
}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement