首页 > 解决方案 > Laravel authorizing actions using Policies via Blade Templates

问题描述

I created a Policy via this command and registered the policy:

php artisan make:policy PostPolicy --model=Post

There is an update policy method already included in the class:

public function update(User $user, Post $post)
{
    return $user->id === $post->user_id;
}

Now I want to use the @can directive:

@can('update', $post)
    <!-- The Current User Can Update The Post -->
@endcan

But I get this error message: "Undefined variable: post"

https://laravel.com/docs/5.5/authorization#creating-policies

标签: phplaravelauthorizationpolicy

解决方案


推荐阅读