繁体   English   中英

我如何才能在Laravel中使用此政策?

[英]How do I get this policy to work in Laravel?

我有一个非常基本的政策

<?php

namespace App\Policies;

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

class CommentPolicy
{
    use HandlesAuthorization;

    public function update(User $user, Comment $comment)
    {
        return true;
    }
}

我称它为景观

@can('update', $comment)
Edit
@endcan

我注册

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

即使它应该总是显示,因为我已经硬编码为true ,却没有任何显示

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

一开始我忘了反斜杠

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM