我在Laravel 5.4上使用并使用Zizaco Entrust来处理我的应用程序中的角色和权限,我正在尝试拉取所有具有"用户"角色的用户,但它返回了此错误
(1/1( 致命错误异常
在 中找不到类"角色">
有关系.php(第 487 行(
这是我的查询
use AppUser; //declare user model
$customer = User::with('roles')->get();
和我的用户模型
<?php
namespace App;
use IlluminateNotificationsNotifiable;
use IlluminateFoundationAuthUser as Authenticatable;
use ZizacoEntrustTraitsEntrustUserTrait;
class User extends Authenticatable
{
use EntrustUserTrait;
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'username', 'email', 'password', 'real_password', 'first_name'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token', 'real_password'
];
public function roles()
{
return $this->belongsToMany('Role','assigned_roles');
}
}
榜样
<?php
namespace App;
use ZizacoEntrustEntrustRole;
class Role extends EntrustRole
{
}
和委托配置
<?php
/**
* This file is part of Entrust,
* a role & permission management solution for Laravel.
*
* @license MIT
* @package ZizacoEntrust
*/
return [
/*
|--------------------------------------------------------------------------
| Entrust Role Model
|--------------------------------------------------------------------------
|
| This is the Role model used by Entrust to create correct relations. Update
| the role if it is in a different namespace.
|
*/
'role' => 'AppRole',
/*
|--------------------------------------------------------------------------
| Entrust Roles Table
|--------------------------------------------------------------------------
|
| This is the roles table used by Entrust to save roles to the database.
|
*/
'roles_table' => 'roles',
/*
|--------------------------------------------------------------------------
| Application User Model
|--------------------------------------------------------------------------
|
| This is the User model used by Entrust to create correct relations.
| Update the User if it is in a different namespace.
|
*/
'user' => 'AppUser',
/*
|--------------------------------------------------------------------------
| Application Users Table
|--------------------------------------------------------------------------
|
| This is the users table used by the application to save users to the
| database.
|
*/
'users_table' => 'users',
/*
|--------------------------------------------------------------------------
| Entrust Permission Model
|--------------------------------------------------------------------------
|
| This is the Permission model used by Entrust to create correct relations.
| Update the permission if it is in a different namespace.
|
*/
'permission' => 'AppPermission',
/*
|--------------------------------------------------------------------------
| Entrust Permissions Table
|--------------------------------------------------------------------------
|
| This is the permissions table used by Entrust to save permissions to the
| database.
|
*/
'permissions_table' => 'permissions',
/*
|--------------------------------------------------------------------------
| Entrust permission_role Table
|--------------------------------------------------------------------------
|
| This is the permission_role table used by Entrust to save relationship
| between permissions and roles to the database.
|
*/
'permission_role_table' => 'permission_role',
/*
|--------------------------------------------------------------------------
| Entrust role_user Table
|--------------------------------------------------------------------------
|
| This is the role_user table used by Entrust to save assigned roles to the
| database.
|
*/
'role_user_table' => 'role_user',
];
有什么想法,请帮忙吗?
确保包在composer.json
中有一个条目。
检查服务提供商是否已注册。
然后,通过运行以下命令重新生成自动加载类映射:
composer dump-autoload