php - 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
解决方案
推荐阅读
- c++ - C++11:std::result_of<> 模板参数与 std::function<>
- java - Docker 映像不会从存储库中提取特定的 JAR
- android - 互联网连接丢失时启动应用程序的 JobScheduler (8.0+)
- android - ARCore 是否支持 SLAM 和 AreaLearning?
- python - 使用Python过滤子字符串后提取数据
- bash - 我想编写一个 shell 脚本,它接受 .txt 文件中给出的命令并执行它们
- java - TableView 在接受用户输入时不填充,但在显式添加新对象时填充
- javascript - 检查链接“img.youtube.com”时添加“类”属性
- javascript - 如何仅使用鼠标坐标清除(或取消绘制)画布?
- security - OAuth:客户端撤销多个访问令牌的访问权限