hesto/multi-auth is a Laravel package for multi auth for laravel.
It currently has 440 GitHub stars and 490.102 downloads on Packagist (latest version v2.0.0).
Install it with composer require hesto/multi-auth.
Discover more Laravel packages by hesto
or browse all Laravel packages to compare alternatives.
Last updated
php artisan multi-auth:install {guard} -fphp artisan multi-auth:install {guard} -f --domainphp artisan multi-auth:install {guard} {service} -f --lucid| Version | Laravel version | Status | Branch | Install | |---------|-----------------|-----------------|--------|------------------------------------------| | 1.x | 5.3 and 5.4 | EOL | 1.0 | composer require hesto/multi-auth 1.* | | 2.x | 5.5, 5.6, 5.7 | Latest | 2.0 | composer require hesto/multi-auth |
With one simple command you can setup multi auth for your Laravel project. The package installs:
composer require hesto/multi-auth
You'll only want to use these package for local development, so you don't want to update the production providers array in config/app.php. Instead, add the provider in app/Providers/AppServiceProvider.php, like so:
public function register()
{
if ($this->app->environment() == 'local') {
$this->app->register('Hesto\MultiAuth\MultiAuthServiceProvider');
}
}
php artisan multi-auth:install {singular_lowercase_name_of_guard} -f
// Examples
php artisan multi-auth:install admin -f
php artisan multi-auth:install employee -f
php artisan multi-auth:install customer -f
Notice:
If you don't provide -f flag, it will not work. It is a protection against accidental activation.
Alternative:
If you want to install Multi-Auth files in a subdomain you must pass the option --domain.
php artisan multi-auth:install admin -f --domain
php artisan multi-auth:install employee -f --domain
php artisan multi-auth:install customer -f --domain
To be able to use this feature properly, you should add a key to your .env file:
APP_DOMAIN=yourdomain.com
This will allow us to use it in the routes file, prefixing it with the domain feature from Laravel routing system.
Using it like so: ['domain' => '{guard}.' . env('APP_DOMAIN')]
php artisan migrate
Go to: http://project_url/GuardName/login
Example: http://myproject.dev/customer/login
If you don't want model and migration use --model flag.
php artisan multi-auth:install admin -f --model
If you don't want views use --views flag.
php artisan multi-auth:install admin -f --views
If you don't want routes in your routes/web.php file, use --routes flag.
php artisan multi-auth:install admin -f --routes
If you want to change the redirect path for once your guard is logged out. Add and override the following method in
your {GuardName}Auth\LoginController:
/**
* Get the path that we should redirect once logged out.
* Adaptable to user needs.
*
* @return string
*/
public function logoutToPath() {
return '/';
}
config/auth.php
app/Http/Providers/RouteServiceProvider.php
app/Http/Kernel.php
app/Http/Middleware/
app/Http/Controllers/{Guard}Auth/
app/{Guard}.php
app/Notifications/{Guard}ResetPassword.php
database/migrations/
routes/web.php
routes/{guard}.php
resources/views/{guard}/
admin guard, don't install it again after you update package to latest version.get to post{guard}.guest middleware to redirect from login page if user is already logged inauth:{guard} middleware to app\Providers\RouteServiceProvider.php. If you have installed multi-auth guard with old version add middleware manually:Route::group([
'middleware' => ['web', 'admin', 'auth:admin'], //you need to add the last middleware to array to fix it (version < v.1.0.6)
'prefix' => 'admin',
'as' => 'admin.',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/admin.php');
});
RouteServiceProviderRoute::group([
'prefix' => 'admin', //if you have older version of package ( < v1.0.4) add this line manually,
'as' => 'admin.', //if you have older version of package ( < v1.0.4) add this line manually (the DOT at the end is important),
'middleware' => ['web', 'admin'],
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/admin.php');
});
routes/{guard}.php and your routes will be named (its important)//New way
Route::get('/home', function () { // <- no {guard} prefix and it has proper name (admin.home)
//content
})->name('home'); // http://your-project/admin/home
//Old way
Route::get('/admin/home', function () { // <- with {guard} prefix
//content
})->name('admin.home'); // http://your-project/admin/home
app.blade.php to auth.blade.phpHey dude! Help me out for a couple of :beers:!