簡體   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