I do have two authentication guard called web and back.
I have seperated routes into two middleware for the auth and backoffice.
When i login with web guard, still i am able to open routes which under the back guard.
Her is my auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'back' => [
'driver' => 'session',
'provider' => 'backs',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'backs' => [
'driver' => 'eloquent',
'model' => App\Backoffice\Backoffice::class,
],
],
heres, is my web.php
Route::group(['middleware'=>'backoffice'], function(){
Route::get('admin_users', 'AdminUserController@index');
Route::get('add_users', 'AdminUserController@create');
});
Route::group(['middleware' =>'auth:web'], function () {
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('agent','AgentController')->names('agent');
Route::get('agent/destroy/{id}', 'AgentController@destroy');
});
here is middleware
backoffice.php
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard('back')->check() == false && $guard != 'back') {
$request->session()->flush();
Auth::logout();
return redirect('backoffice/login');
}
return $next($request);
}
here is my model.
namespace App\Backoffice;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Backoffice extends Authenticatable
{
protected $table = 'users';
protected $guard = 'back';
protected $guarded =[];
}
please let me know if you need further information.