Adding custom middleware to protect user admin area
In this section, I am going to use middleware to protect an admin area. We will build this area as our user admin area later, but for now I just want to show how to implement middleware that makes sure that the user is the admin.
Getting ready
Base install of Laravel with users imported.
How to do it…
- First, I am going to add a new field to the user table to set some users as admins:
> php artisan make:migration alter_user_table_add_is_admin
- I will edit the
database/migrations/2016_05_21_132909_alter_user_table_add_is_admin.php
file so that it looks as follows: - Then, I will make middleware ...
Get Laravel 5.x Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.