我有一个非常基本的政策
<?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
进行了硬编码,但没有任何显示
答案 0 :(得分:0)
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
\App\Models\Comment::class => \App\Policies\CommentPolicy::class,
];
我忘了开头的反斜杠