artisticre's avatar

Authentication question

I have an app I am working on. It is rerouting based on roles. It works well but something I discovered is if a team member submits an application it works. But if a different team member logs in as themselves, they can view the other team members application. How do I go about restricting access to the applications to the user that submitted them?

0 likes
3 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

Just example

public function update(Request $request, Post $post) {
    if ($post->author !== auth()->user()->id || auth()->user()->cannot('edit posts'))
        abort(404);// or redirect, or whatever action 
    }
    //rest of method if all okay
}

Also see https://gist.github.com/jimgwhit/ed44a6c81815804f1ab910ce9eb88d84

There is a scope example. Use your authorization I use custom.

Also Jeffrey has three or four free authorization videos in the free from scratch series.

Please or to participate in this conversation.