【问题标题】:laravel 5.1 authserviceprovider define a permissionlaravel 5.1 authserviceprovider 定义一个权限
【发布时间】:2015-12-05 02:29:58
【问题描述】:

试图在 Laravel 5.1 中整理出这个新的 AuthServiceProvider。

<?php

namespace App\Providers;

use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{

public function boot(GateContract $gate)
{
    $this->registerPolicies($gate);

    $gate->define('test-permission', function ($user) {
        return true;
    });

}

在我的刀片中我尝试

@if (Gate::allows('test-permission'))
    hello world.
@endif

我得不到爱。如果我把它改成Gate::denies('test-permission') hello world 渲染。

最终我想从我的 Entrust 数据中提取我的权限以将我的权限迁移到 Laravel 5.1 环境。

【问题讨论】:

    标签: laravel authentication laravel-5.1


    【解决方案1】:

    Laravel 只会在有登录用户时调用你的闭包。

    如果没有登录用户,Laravel 将始终拒绝一切。


    如果您登录,您可能还没有properly registeredAuthServiceProvider

    【讨论】:

    • 我已登录 - 但也许我需要更改我的身份验证以使其与 5.1 兼容。我按照说明进行操作。我 dd(Auth::user()) 看起来不错。如果 (Auth::check()) 返回 true。
    • 在您的define 回调中尝试dding。达到了吗?
    • 不——在 AuthServiceProvider 中的任何地方 dd 什么都不做
    • 你确定它实际上是在config/app.phpproviders数组中注册的吗?
    • 像这样:'Illuminate\Auth\AuthServiceProvider',
    猜你喜欢
    • 2016-08-24
    • 1970-01-01
    • 2016-09-13
    • 1970-01-01
    • 2016-01-09
    • 2015-09-20
    • 2015-07-29
    • 2017-07-22
    • 2016-01-24
    相关资源
    最近更新 更多