Laravel 5.4 Redirection to Custom Url After Login

Laravel 5.4 redirection to custom url after login

You need to add the following lines into your LoginController:

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;

use Illuminate\Foundation\Auth\AuthenticatesUsers;

use Illuminate\Http\Request;

class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/

use AuthenticatesUsers;

protected function authenticated(Request $request, $user)
{
if ( $user->isAdmin() ) {// do your magic here
return redirect()->route('dashboard');
}

return redirect('/home');
}
/**
* Where to redirect users after login.
*
* @var string
*/
//protected $redirectTo = '/admin';

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
}

Redirect after login laravel 7

By default In your LoginController just replace

protected $redirectTo = '/home';

TO

protected $redirectTo = '/details';

But if you use own authenticate so you use like this

public function authenticate(Request $request)
{
$credentials = $request->only('email', 'password');

if (Auth::attempt($credentials)) {
// Authentication passed...
return redirect($this->redirectPath());
//return redirect()->intended('/details');
}
return redirect($this->redirectPath());

}

Laravel - Redirect users to custom urls based on language field on login form

If you have a language input field in the form, you can just use:

$request->input('user_language', 'default');

Other than that, your code should work as long as you have a route supporting the language.

Laravel 5.4 Redirect after authentication

The default Laravel login controller sets the value of $redirectTo to '/home'. You need to update that to the new route as that defines where it gets redirected to after login.



Related Topics



Leave a reply



Submit