Laravel 5.1 中的错误 Acl/Laravel
Error Acl/Laravel in Laravel 5.1
我在系统中创建用户角色和权限时遇到问题。
我正在使用 Package acl / laravel,文档描述了这些阶段。我在Get User Roles之前写了如下代码UserController:
文档:https://github.com/kodeine/laravel-acl/wiki/Create-Roles
$users = User::all();
$users->getRoles();
return view('users.index', compact ('users'));
错误:
BadMethodCallException in Macroable.php line 81:
Method getRoles does not exist.
出了什么问题,我该如何解决?
问题是 User
对象存在 getRoles
方法,当您在 $users
变量中使用 User:all()
时,您将获得所有用户,而不是单个用户。
所以你可以这样做:
$users = User::all();
return view('users.index', compact ('users'));
并且在您的 Blade 模板中,您可以在 foreach
循环用户 getRoles()
方法中为单个用户显示它们
我在系统中创建用户角色和权限时遇到问题。
我正在使用 Package acl / laravel,文档描述了这些阶段。我在Get User Roles之前写了如下代码UserController:
文档:https://github.com/kodeine/laravel-acl/wiki/Create-Roles
$users = User::all();
$users->getRoles();
return view('users.index', compact ('users'));
错误:
BadMethodCallException in Macroable.php line 81:
Method getRoles does not exist.
出了什么问题,我该如何解决?
问题是 User
对象存在 getRoles
方法,当您在 $users
变量中使用 User:all()
时,您将获得所有用户,而不是单个用户。
所以你可以这样做:
$users = User::all();
return view('users.index', compact ('users'));
并且在您的 Blade 模板中,您可以在 foreach
循环用户 getRoles()
方法中为单个用户显示它们