0

Hello i am getting stuck on this how to access same route in default auth and tsr. My auth.php looks like below:-

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
        'hash' => false,
    ],
    'tsr' => [
        'driver' => 'session',
        'provider' => 'tsrs',
    ],
],

and this is my below web.php file:-

 //Tsr Routes
 Route::get('/tsr', 'Tsr\TsrController@index')->name('tsrs.dashboard');
 Route::get('/tsr/login', 'Auth\Tsr\LoginController@login')->name('tsrs.auth.login');
 Route::post('tsr/login', 'Auth\Tsr\LoginController@loginAdmin')->name('tsrs.auth.loginAdmin');

Route::group(['middleware' => ['auth', 'auth:tsr'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
 Route::get('/home', 'HomeController@index')
 Route::resource('regular_meetings', 'Admin\RegularMeetingsController');
 Route::post('regular_meetings_mass_destroy', ['uses' => 'Admin\RegularMeetingsController@massDestroy', 'as' => 'regular_meetings.mass_destroy']);
});

Kernel.php below:-

protected $routeMiddleware = [
    'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
    'can' => \Illuminate\Auth\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    'approved' => \App\Http\Middleware\ApproveMiddleware::class,
    'usergate' => \App\Http\Middleware\UserGate::class,
];

Middleware below:-

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @param  string|null  $guard
 * @return mixed
 */
public function handle($request, Closure $next, $guard = null)
{
    if (Auth::guard($guard)->check()) {
        return redirect('/admin/home');
    }

    return $next($request);
  }
}

Now you see that the I have added three routes that will be accessible to all two middlewars.

Now problem is that Not able to login as access the routes form both logged in users . If remove auth:tsr fro middleware it will work only auth users. Tsr Login View is different and User login View is different. Please help me how to resolve this issue.

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
user
  • 51
  • 9
  • Possible duplicate of [How to use multiple Middleware groups on Laravel?](https://stackoverflow.com/questions/52695502/how-to-use-multiple-middleware-groups-on-laravel) – Ch Asad Ur Rehman Sep 22 '19 at 08:05
  • @ChAsadUrRehman this answer seems to be using only one guard that is user i am using multiple guards. check my question before duplicating – user Sep 22 '19 at 08:09
  • use in controller instead of routes.. – Tanvir Ahmed Sep 22 '19 at 10:56
  • I would suggest to create a new middle where you check condition of both middleware in OR condition and that way you can use your routes in both the middleware. – Vishal Tarkar Sep 23 '19 at 11:44

0 Answers0