Laravel 5.5 permissions based on user id
For a Laravel 5.5 project I solved a permission problem that I’d like to share in case someone else can benefit.
Problem:
The structure of our urls look like this:
users/5/companies
Which will show all the companies for user 5. I however wanted to limit it so that only user 5 may see user/5 company listings. User/4 or another use should see access denied when viewing /users/5/companies.
My current route was defined this way in routes/web.php: