laravel redirect with username code example
Example 1: how to redirect to another page after login in laravel
protected function authenticated(Request $request, $user) {
if ($user->role_id == 1) {
return redirect('/admin');
} else if ($user->role_id == 2) {
return redirect('/author');
} else {
return redirect('/blog');
}
}
Example 2: how to redirect to another page after login in laravel
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected function authenticated(Request $request, $user)
{
if ( $user->isAdmin() ) {
return redirect()->route('dashboard');
}
return redirect('/home');
}
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
}