Support
Quality
Security
License
Reuse
kandi has reviewed SpringBoot-Shiro-Vue and discovered the below as its top functions. This is intended to give you an instant insight into SpringBoot-Shiro-Vue implemented functionality, and help decide if they suit your requirements.
提供一套基于Spring Boot-Shiro-Vue的权限管理思路.前后端都加以控制,做到按钮/接口级别的权限。(当前新版本已移除shiro依赖,简化了配置)
核心
每个登录用户拥有各自的N条权限,比如 文章:查看/编辑/发布/删除
后端
@RequiresPermissions("article:add")
前端
"userPermission":{
"menuList":[
"role",
"user",
"article"
],
"roleId":1,
"nickname":"超级用户",
"roleName":"管理员",
"permissionList":[
"article:list",
"article:add",
"user:list",
],
"userId":10003
}
具体实现
npm install
npm run dev
QUESTION
Why Laravel Policy is not working in View/Blade?
Asked 2022-Mar-18 at 12:26I tried to filter who can edit/delete on my app using policies but it's not working. Trying to use it on blade.
QuestionPolicy.php
const UPDATE = 'update';
const DELETE = 'delete';
/**
* Check if user can update a question.
*/
public function update(User $user, Question $question): bool
{
return $question->isAskedBy($user) || $user->isModerator() || $user->isAdmin();
}
/**
* Check if user can delete a question.
*/
public function delete(User $user, Question $question): bool
{
return ($question->isAskedBy($user) || $user->isModerator() || $user->isAdmin()) && !$user->isBanned();
}
question.blade.php
@can(App\Policies\QuestionPolicy::UPDATE, App\Models\User::class, App\Models\Question::class)
<a class="text-sm font-light text-gray-600" href="#">Edit</a>
@endcan
@can(App\Policies\QuestionPolicy::DELETE, App\Models\User::class, App\Models\Question::class)
<a class="text-sm font-light text-gray-600" href="#">Delete</a>
@endcan
Did I do it wrong? Tried to login as admin and also the user who created the question but the link to edit/delete is not rendered.
ANSWER
Answered 2022-Mar-18 at 12:26You need to pass the actual instance of the question (and you don't need to pass the user class) if the policy is regarding a specific question:
@can(App\Policies\QuestionPolicy::UPDATE, $question)
<a class="text-sm font-light text-gray-600" href="#">Edit</a>
@endcan
@can(App\Policies\QuestionPolicy::DELETE, $question)
<a class="text-sm font-light text-gray-600" href="#">Delete</a>
@endcan
$user
in the policy is always the currently signed in user.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit