check signed in user can edit a place

Posted 2 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.