Create a configurations
Table
In your database, create a table named configurations
with columns id
(primary key), name
(string), and value
(boolean). Create this table with a migration.
Insert a record into this table with name
set to "maintenance-mode" and value
set to false
.
Maintenance Mode Middleware
You are going to create middleware that redirects users to a maintenance mode page (that you design yourself) at the URL path /maintenance
if there is a record in the configurations
table with a name
of "maintenance-mode" and its value
is true
. If that record's value
is false
, users should not be redirected to that page. Name the middleware class MaintenanceMode
. This middleware should only apply to unauthenticated routes except for the following:
- GET
/login
(We want to be able to login and logout to toggle this configuration) - POST
/login
- POST
/logout
- GET
/maintenance
. (If theMaintenanceMode
middleware is applied to this route, you'll end up with an infinite loop of redirects.)
To create middleware, use the command php artisan make:middleware MaintenanceMode
.
A Settings Page
Create an admin page at /admin
. This page will have a form with one checkbox that will toggle the value
column of the record in the configurations
table with a name
of maintenance-mode
.
Make sure that there is a registered account with an email of admin@usc.edu
and a password of laravel
.
For the admin@usc.edu
user, set the role to admin
.
Next, create middleware that is attached to the admin route you just created. Only authenticated users with a role of admin
should be allowed to visit this page. Otherwise, redirect to Laravel's 404 page using abort
.
Submission
Verify that your app has been deployed to Heroku, which you set up in Assignment 2.
Send an email to Brighton and me with the URL to your GitHub repository with the subject: "ITP 405 - Assignment 6".