使用 Laravel 策略授权 Nova

问题描述

我目前正在将 Nova 用于我的后台应用程序,并尝试根据用户的角色授予用户身份验证。我已经编写了一些策略,除了一个之外,它们都有效。我一遍又一遍地浏览它,看看我是否遗漏了什么,但我什么也没找到。我需要你们帮助再看一眼,以帮助我弄清楚我做错了什么。这是我正在使用的代码

订单政策

<?php

namespace App\Policies;

use App\Models\Order;
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class OrderPolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view any order.
     *
     * @param  \App\User  $user
     * @return mixed
     */
    public function viewAny(User $user)
    {
        return $user->hasAnyRole(['crm']);
    }
}

订购 nova 资源

class Order extends Resource
{
    public static function indexQuery(NovaRequest $request,$query)
    {
        return $query->where('status_id','paid');
    }

    public static $model = 'App\Models\Order';

    public static $title = 'id';

    public static $search = [
        'id','reference'
    ];

    public function fields(Request $request)
    {
        return [
            // fields that should be displayed
        ];
    }

   // other functions
}

AuthServiceProvider

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // other policies
        'App\Models\Order' => 'App\Policies\OrderPolicy',];

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

        // ....
    }
}

这个政策我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)