Using Laravel 5.4. I have a custom front-end authentication middleware and login controller which works, apart from the post-login redirection. I am using Redirect::intended()
to go to the originating page after logging in, but instead it goes to the default page.
Middleware:
public function handle($request, Closure $next, ...$guards)
{
if (auth()->check() && (auth()->user()->is_public == 1)) {
return $next($request);
}
return redirect('/client-login');
}
Controller:
use AuthenticatesUsers;
protected $redirectTo = '/';
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
protected function attemptLogin(Request $request)
{
if (auth()->attempt(['email' => $request->email, 'password' => $request->password, 'is_public' => 1])) {
return Redirect::intended($this->redirectTo);
}
}
Route:
Route::group(['middleware' => ['frontend']], function() {
Route::get('test', 'HomeController@test');
});
Users always get redirected to /
. Instead I want them to be redirected to the page they were tryign to access before they got intercepted by the auth.
via GluePear