Codementor Events

How to use Laravel multiple guards

Published May 27, 2019
How to use Laravel multiple guards

The story begins 2 years ago when i started using the Amazing Laravel Framework, and discovered the multiple guards system which made me really feel Wow now ( Users authentications are separated from the Admin authentications ). but there were one problem about it, that i need to create the hole guard requires myself ( views, middlewares, controllers, models and many other stuffs ) and after a while i decided to create my own Laravel app template which i clone each time which has ( Admin and User guards ) works together as expected and reduce the development time, But one day i received a project which needs other guard ( Teacher, Parent and Student ) now we don’t need Users anymore here, so now my own Laravel app template became a little useless because i will create the guards requires myself again from scratch, at this time i felt really bad about creating everything from scratch, but i came with an idea which changed the way i develop Laravel apps forever MultiAuthCommand when i started to develop this command i felt bad because it was a challenge to me which i really loved to work on it, after almost 1 and half now this command serve me a lot, it save me a lot of times as it’s flexible because recently i added a theme option to it which has prebuilt views for different Admin panels from the internet, and the use of this command is really simple.

Usage

  • How to install
composer require imokhles/multi-auth-command
  • Add this provider to your config/app.php ( no need for Laravel 5.5 and above )
iMokhles\MultiAuthCommand\MultiAuthCommandServiceProvider::class
  • list all supported themes
php artisan make:multi_auth:list_themes
  • how to create Admin guard + select one of supported themes
php artisan make:multi_auth Admin --admin_theme="startui"
  • copy theme files to
PROJECT_DIR/public/THEME_NAME/*css,js,img,fonts
  • if needed change theme folder name under public ( inside config/[guard]_config.php )

THAT’s ALL check the github page to understand more about this package.

Discover and read more posts from Mokhlas Hussein
get started
post commentsBe the first to share your opinion
Show more replies