dimanche 6 décembre 2015

Prevent authenticated user to view other users profile on Laravel 5

I want to use Laravel 5 AuthServiceProvider to prevent logged in user to view other users profile. I'm using route like this user/1. How can I compare if the logged in user ID is match with the ID in the URL. If not then can't proceed.

Here's the following code I'm trying:

$gate->define('view-profile', function($user) {
    return Auth::user()->id === $id;
});

However, the above code doesn't work as I can't pass the correct ID from the URL. Can anyone please help?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire