jeudi 7 juin 2018

Lumen policy not working in v5.6

I am working in lumen v5.6. In my project I have two policies class name UserPolicy and CommentPolicy. Now I want to delete comment and I define archive method in CommentPolicy class but when I can it from my comment controller then this method is not call because I need to implement some logic in this method. Now I don't know that why the CommentPolicy method is not called from Comment Controller.

Below is my code that I code

Register policy in auth service provider

Gate::policy(User::class, \App\Policies\CommentPolicy::class);

Policy class

<?php
namespace App\Policies;
use App\Models\User;
use App\Models\PostComment;
class CommentPolicy
{

    public function archive(User $currentUser, PostComment $comment)
    {
        echo "Policy<pre>";
        print_r($comment->toArray());
        exit;
        return $currentUser->id === $comment->user_id;
    }

}

My controller method

public function archiveComment(PostCommentRequest $request){
        $user = $this->getCurrentUser($request);
        $comment = $this->comment->getCommentById($request->get('data')['comment_id']);
        if($user->can('archive', $comment)){
            die('policy call');
        }
        die('policy not called');
    }

Now my concern is that I want to receive data in comment policy class instead of UserPolicy class and implement my logic of delete comment authorization.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire