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
Warning: Imagejpeg() [Function:Imagejpeg]: Gd-Jpeg: Jpeg Library Reports Unrecoverable Error
Using Square Brackets in Hidden HTML Input Fields
Concatenating a String and Primary Key Id While Inserting
Creating Anonymous Objects in PHP
Autoloading Classes in PHPunit Using Composer and Autoload.Php
How to Handle $_Post Data in MVC
How to Make PHP Generate Chunked Response
Do SQL Connections Opened with Pdo in PHP Have to Be Closed
How Get All Values in a Column Using PHP
Will Enabling Xdebug on a Production Server Make PHP Slower
How to Write a Recursive Regex That Matches Nested Parentheses
MySQL Retrieve Variable from Stored Procedure in PHP Pdo
How to Deal with Backslashes in JSON Strings PHP
What Is the Use of '\G' Anchor in Regex
Php: Variable Not Working Inside of Function
How to Resolve "Must Be an Instance of String, String Given" Prior to PHP 7