我从GitHub Link跟踪了zizac/entrust安装教程并遇到了错误:
类名必须是一个有效的对象或在VAR的字符串/ WWW/HTML/laravel_test /供应商/ zizaco /委托/ SRC /命令/ MigrationCommand.php上线86
MigrationCommand.php文件网址:链接
Outut:
php artisan entrust:migration
Tables: roles, role_user, permissions, permission_role
A migration that creates 'roles', 'role_user', 'permissions', 'permission_role' tables will be created in database/migrations directory
Proceed with the migration creation? [Yes|no] (yes/no) [yes]: yes
Creating migration...
PHP Fatal error: Class name must be a valid object or a string in /var/www/html/laravel_test/vendor/zizaco/entrust/src/commands/MigrationCommand.php on line 86
Run Code Online (Sandbox Code Playgroud)
命令:php artisan vendor:发布成功.
文件:config/entrust.php存在.
我没有改变config/auth.php文件的任何选项 - auth.php.怎么解决?
我安装并配置了Laravel 5.2,它运行正常,因为User ACL我zizaco/entrust在运行此命令时安装了包php artisan migrate(用于创建roles,permissions表等),导致以下错误
[Illuminate\Database\QueryException] SQLSTATE [HY000]:常规错误:1215无法添加外键约束(SQL:alter table
role_useradd constraint role_user_user_id_foreign foreign key(user_id)引用``(id)on update cascade on update cascade)[PDOException] SQLSTATE [HY000]:常规错误:1215无法添加外键约束
可能是什么原因 ?我错过了什么吗?我遵循委托网站的逐步指导方针
嗨,大家好,使用最新的Laravel 5.2.2和Entrust("zizaco /委托":"5.2.x-dev")我遇到这个错误,不知道如何解决这个问题
Call to undefined method Zizaco\Entrust\EntrustServiceProvider::hasRole()
Run Code Online (Sandbox Code Playgroud)
我在HomeController.php上测试了这段代码
use Entrust;
class HomeController extends Controller
{
public function index()
{
if (Entrust::hasRole('admin')) {
echo "string";
}
return view('home');
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的config/app.php服务提供商
Zizaco\Entrust\EntrustServiceProvider::class
Run Code Online (Sandbox Code Playgroud)
config/app.php外观别名
'Entrust' => Zizaco\Entrust\EntrustFacade::class
Run Code Online (Sandbox Code Playgroud)
我也已经生成了所需的模型
我在这里错过了什么吗?提前致谢
我在Laravel 5.1中使用Zizaco /委托.我想通过使用复选框显式授予特定角色的权限.这是我的代码:
获取角色:
fetchRoles: function(){
this.$http.get('api/role',function(data){
this.$set('roles',data);
});
}
Run Code Online (Sandbox Code Playgroud)
获取权限:
fetchPermissions: function(){
this.$http.get('api/permission',function(data){
this.$set('permissions',data);
});
}
Run Code Online (Sandbox Code Playgroud)
以下是分配角色和权限的表:
<table class="table table-bordered table-responsive">
<thead>
<th>Permissions/Roles</th>
<th v-for="role in roles">
@{{ role.display_name }}
</th>
</thead>
<tbody>
<tr v-for="permission in permissions">
<td>@{{ permission.display_name }}</td>
<td v-for="role in roles">
<input type="checkbox" value="@{{ permission.id }}" name="roles[@{{ role.id }}][permissions][]">
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
<button type="submit" class="btn btn-primary">Alter Permission</button>
</td>
</tr>
</tfoot>
</table>
Run Code Online (Sandbox Code Playgroud)
输出如下: 输出的屏幕截图
权限也通过以下方法成功分配:
public function changePermission(Request $request){
$input = $request->all(); …Run Code Online (Sandbox Code Playgroud) 因此,我正在阅读有关使用laravel策略为我的应用程序资源授予权限的信息,但是尽管我遵循了该教程,但似乎还是有问题。
我有一个用户模型,除具有Entrust角色“ Admin”或“ Broker” 的其他用户外,无法通过HTTP请求创建。我了解并成功地将其用于其他操作(例如为用户编制索引)如下:
在AuthServiceProvider.php私有$policies数组内部,我用UserPolicy类似的类注册了该User类
class AuthServiceProvider extends ServiceProvider {
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
User::class => UserPolicy::class,
Insured::class => InsuredPolicy::class
];
public function boot(GateContract $gate)
{
$this->registerPolicies($gate);
}
}
Run Code Online (Sandbox Code Playgroud)
定义UserPolicy控制器类:
class UserPolicy {
use HandlesAuthorization;
protected $user;
public function __construct(User $user) {
$this->user = $user;
}
public function index(User $user) {
$is_authorized = $user->hasRole('Admin');
return $is_authorized;
}
public function show(User $user, User $user_res) {
$is_authorized = ($user->id == …Run Code Online (Sandbox Code Playgroud) 我刚刚安装了Entrust,基于Laravel 5.2为我的应用程序添加了基于角色的权限.但是当我尝试执行时
php artisan vendor:publish
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
PHP致命错误:"在第72行的../vendor/zizaco/entrust/src/Entrust/EntrustServiceProvider.php中调用未定义的方法Illuminate\Foundation\Application :: bindShared()"
谁能帮我?
我已经在我的Laravel 5.1应用程序中安装了Entrust软件包,方法是将它添加到我的composer.json文件并运行composer update并按照所有说明进行操作.我试图使用他们的中间件来保护一些路由,但我得到以下异常:
ReflectionException in Container.php line 741:
Class App\Http\Zizaco\Entrust\Middleware\EntrustPermission does not exist
Run Code Online (Sandbox Code Playgroud)
这是我的composer.json文件的内容:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"LaravelCollective/html": "5.1",
"zizaco/entrust": "dev-laravel-5",
"yajra/laravel-datatables-oracle": "~5.0",
"davejamesmiller/laravel-breadcrumbs": "~3.0",
"intervention/image": "dev-master",
"doctrine/dbal": "2.5.1",
"thujohn/twitter": "~2.0",
"fzaninotto/faker": "^1.5",
"cviebrock/image-validator": "2.0.*@beta"
},
"require-dev": {
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database",
"app/Http/Helpers"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": …Run Code Online (Sandbox Code Playgroud) 为什么运行这个时不会创建文件entrust.php:
php artisan vendor:publish
Run Code Online (Sandbox Code Playgroud)
我正在关注这个配置,这是我的composer.json
"zizaco/entrust": "5.2.x-dev"
Run Code Online (Sandbox Code Playgroud)
"您还可以发布此软件包的配置,以进一步自定义表名称和模型名称空间.只需使用php artisan vendor:publish,将在app/config目录中创建entrust.php文件." 但是没有创建文件entrust.php.我能做什么?这很奇怪.
我正在使用 entrust 包来管理角色,并且我使用通行证进行身份验证,因为它是 API 的。
其实我需要的是想检查用户有一个角色,
我试过下面的代码,但它不起作用
public function Adminlogin()
{
if(Auth::attempt(['email' => request('email'), 'password' => request('password')]))
{
$user = Auth::user();
if($user->hasRole('admin'));
{
$success['token'] = $user->createToken('MyApp')->accessToken;
return response()->json(['success' => $success], $this->successStatus);
}
return response()->json(['error'=>'Abort'], 403);
}
else
{
return response()->json(['error'=>'Unauthorised'], 401);
}
}
Run Code Online (Sandbox Code Playgroud)
我只想在用户具有管理员角色时生成访问令牌,如果用户没有管理员角色,则显示中止消息。
我是laravel的全新人物.我安装了laravel 5.2.我在laravel完成了CRUD.现在我想整合laravel身份验证包.所以我选择zizaco \委托.
我按照文档链接的每个步骤.但我不明白出了什么问题.在doc中没有提到我必须在哪个文件中添加以下代码.
$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();
Run Code Online (Sandbox Code Playgroud)
和其他下面的代码在文档中.
甚至
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
Run Code Online (Sandbox Code Playgroud)
没有提到有关实现类.
我做
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use …Run Code Online (Sandbox Code Playgroud) entrust ×10
laravel ×9
laravel-5.2 ×4
php ×4
laravel-5 ×3
laravel-5.1 ×3
artisan ×1
authorize ×1
laravel-5.5 ×1
policies ×1
vue-resource ×1
vue.js ×1