Authorisation/Authentication features in Laravel Part 2 - Guards

Jun 25, 2017 guards laravel authentication php admin multiauthentication user
Guards define how the application retrieves and sends information about the user; whether it’d be by the class method of cookies or api tokens. Guards are slightly more technical but using guards allows us to have multiple authentication. So imagine we have a web app with a customer and an admin. At first thought we could customise the users table to have a column labelled ‘Admin’ and with that we can check whether or not a user is an admin and perform the necessary redirects.

This is where things get cool and organised. Guards allows the developer to create a separate table for Admins and with that table we can use guards to tell the web app to authenticate the user against the Admin table data.

So instead of clumping our users and admins in a large data set, we’re able to separate the user type not by a column but by a brand new table.

In Laravel the way it works is we define a guard, the guard uses the provider and the provider tells the app which table to retrieve and authenticate the user.

For a full example of a multiple authentication using laravel guard see -

If you found the following info helpful, I'm happy to accept any donations of the following cryptocurrencies.

  • Bitcoin - 17DTiPExzP9StqveW428acEyB4mVMfKbiK
  • Ethereum - 0x87B8307FD20dc90cc05c94905Ec593134D32B6FF
  • Litecoin - LZMiz5U5sVq9doMLYE3gfLJrxCQDKuyCmU
  • Neo - AXv71WB38ajc1KUUEnxQKhynLLPc4BapVb