Skip to content

Instantly share code, notes, and snippets.

@tobyokeke
Last active March 17, 2021 06:02
Show Gist options
  • Save tobyokeke/c5aac34ac81ca7c999e2a12fa7f3296e to your computer and use it in GitHub Desktop.
Save tobyokeke/c5aac34ac81ca7c999e2a12fa7f3296e to your computer and use it in GitHub Desktop.
Laravel Multi-Auth
<?php
Route::group(['prefix' => 'v1'],function(){
//general unauthenticated routes here
Route::group(['prefix' => 'customer'],function(){
Route::post('sign-up','CustomerController@signUp');
//unauthenticated routes for customers here
Route::group( ['middleware' => ['auth:customer','scope:customer'] ],function(){
// authenticated customer routes here
Route::post('dashboard','CustomerController@dashboard');
});
});
Route::group(['prefix' => 'staff'],function(){
Route::post('sign-up','StaffController@signUp');
//unauthenticated routes for customers here
Route::group( ['middleware' => ['auth:staff','scope:staff'] ],function(){
// authenticated staff routes here
Route::post('dashboard','StaffController@dashboard');
});
});
});
@hunnysyno
Copy link

In below code, scope:customer must be scopes:customer if you have added middleware as scopes in Kernel.php

Route::group( ['middleware' => ['auth:customer','scope:customer'] ],function(){ // authenticated customer routes here Route::post('dashboard','CustomerController@dashboard'); }); });

I have tested on Laravel 8, it worked perfectly. Thanks for sharing required tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment