Laravel 4 Prevent Authenticated users from viewing other user profiles
laravel-4, php, restful-authentication
Solution
In your `Auth` filter you can access the route parameter (`'user/{id}'`) and can check logged in user's `id` with the `id` passed in the `url` like
Route::filter('auth', function($route)
{
// get the id from rouqe
$id = $route->getParameter('id');
if( Auth::check() && Auth::user()->id != $id) {
// not authenticated user, so access is denied
return Redirect::to('/');
}
});
Problem
I am wondering how in `laravel 4` the following is possible. I have a filter to check if a user is authenticate on all routes that have user/*. My filter works as it is suppose to but lets say that a user is logged in their `url` will look something like this `user/id`. How do I prevent an authenticated user from viewing another user?