check signed in user can edit a place

Posted 4 months ago by michaelnguyen547

I have this check to make sure the signed in user can edit a post


if ($post->author_id !== Auth::id()) {
            return response()->json([
                'message' => 'The given data was invalid',
                'errors' => [
                    'passenger' => 'Attempt to update unauthorized resource'
                ]
            ], 422);
        }

I have the check in multiple places in multiple controllers. What is the best way to do this without copy/paste everywhere when I need to check?

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

Reply to

Use Markdown with GitHub-flavored code blocks.