Enter your keyword

Laravel Multi Authentication

Laravel Multi Authentication

Laravel is very powerful framework in that it comes with most of the things you have to worry about, are already settled for you. Today I wish to discuss a very pivot feature in most web applications; authentication.

Most web application you will have some sort of login page for authenticating users usually with a username – password combination. Laravel has simplified user authentication to the extent that you will have it up and running in pretty much two steps. But have you ever been confronted with the possibility of having multiple (different) groups of users, that you wish to separate resources for.

The simplest example can be the administrators of your web application vis a vis the regular users of the application. If you coming from a background of content management systems like WordPress you know exactly what am talking about; the  famous /wp-admin back-end section of your website.

Multi authentication doesn’t not end with creating a separate administrator side for your web application. Imagine your creating an e-commerce website where third parties are able to sell through your platform; you might be confronted with the decision to layout different sections of the platform for different users say; users (customers), sellers (third party shops), and administrators. In today’s tutorial I will show you how to setup such a configuration using the Laravel multi authentication package I created for just that.

Installation

Make sure you’ve set up the default basic Laravel authentication prior to this. If your not sure how to go about that, you may read my other tutorial on setting up Laravel authentication.

$ composer require bmatovu/multi-auth

Register Service Provider

Only for Laravel versions 5.3 and 5.4. For v5.5 and above; this package’s service provider and facade alias will be discovered automatically upon installation.

In config/app.php

Register Alias

In config/app.php

If you’ve cached your configurations, you need to run;

$ php artisan config:cache

Install Package

$ php artisan multi-auth:install {guard}

Default guard is named: admin be sure to use a name that suits your needs. This command will scaffold configurations, controllers, middleware, migrations, models, routes, and views; to get you started.

See a list of files created, or affected at files.md

Run Database Migrations

$ php artisan migrate

Usage

http://127.0.0.1:8000/{guard}

Extras:

Check guards:

Check routes:

To find out which new routes have been created for your guard

$ php artisan route:list

I Need help!

Feel free to open an issue on Github. Please be as specific as possible if you want to get help.

Reporting bugs

If you’ve stumbled across a bug, please help us by leaving as much information about the bug as possible, e.g.

  • Steps to reproduce
  • Expected result
  • Actual result

This will help me to fix the bug as quickly as possible, and if you’d like to fix it yourself feel free to fork the package on GitHub and submit a pull request!


Thank you, for following through. I will be writing a another tutorial on how to go about Laravel multi-authentication from scratch for those that are interested in DIY (Do It Yourself) kind of approach.