Dronax
391
6
Laravel

Check if user is not owner of post, and if user owner of comment parent in Custom Request

Posted 6 months ago by Dronax

I have a custom request with authorize method:

public function authorize()
{
    return Auth::user() ? $this->post->user_id !== Auth::user()->id && ! $this->parent_id && $this->user_id == Auth::user()->id : true;
}

I need prevent adding comment: (if user is owner of post, if user not owner of comment parent). How I can do it? My condition is not work. I get 403..

In table comments I have: post_id, user_id, parent_id, body. In model comment and post I have relations.

Please sign in or create an account to participate in this conversation.