Laravel 5: Multi-level authorization: coding explained

There are differences between Laravel provided single-auth and multi-auth layer approach here. Lets take a look at these differences.

Differences mentioned above do not mean that anything was invented, coded-in or added to original Laravel 5.2 codebase.

Multi-level authentication offered here uses Laravel builtin’ tools and capacity. Let’s see all changes: where they have been done and why.
When request arrives, it goes through \app\Http\routes.php file, which reads URI and redirects it to proper place.

Of course above is simplified, but in general it serves our purpose here.

Standard Laravel 5 installation puts all routes into one file. I personally do not like it, as it can quickly make such file very long, even with Laravel providing for some tools to make routes serve multiple redirects.

So I keep \app\Http\routes.php file as a switchboard, pulling specific route from \app\Http\Routes folder.


And this is my \app\Http\routes.php file:


Let’s take a look at code above one by one.


Above code takes you to a GatewayController.

GatewayController just selects proper view (gateway.blade.php) and redirects there.

In laravel you do not need to add “blade.php” to let system know, which view template you want.

Actually, you could do without controller in this case and you could use closure.

Above code would work too, but just in case, if sometime in the future, you’d want to pass some dynamic data to your view, controller gives you more flexibility. That is the reason I used controller, instead of closure.

So, now we are on index page.


Lets click on Student gateway and see where it takes us.


I will split login, registration, password recovery into 3 sections.
Otherwise this article would be very long.