What exactly happens? Did you try using dd() to check the user?
Also be aware that it will redirect to intended if the user tried to visit a certain page before hitting this :)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using laravel/ui and everything works fine except I want to redirect user conditionally. I want to redirect user depend on roles, This is my routes:
Auth::routes(['register' => false, 'reset' => false]);
Route::middleware('auth')->group(function(){
Route::get('/', [HomeController::class, 'index'])->name('home');
});
and this is RouteServiceProvider:
class RouteServiceProvider extends ServiceProvider
{
public const HOME = '/';
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::middleware('api')
->prefix('api')
->group(base_path('routes/api.php'));
Route::middleware('web')
->group(base_path('routes/web.php'));
});
}
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
}
}
and inside LoginController I have these code:
class LoginController extends Controller
{
use AuthenticatesUsers;
protected function redirectTo()
{
if (auth()->user()->can('dashboard')) {
return '/';
}
return '/documents';
}
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
but I cannot make it work
@Armani Try this
dd(session()->get('url.intended'));`
If this returns /, then that means it has already been set to use /, as you tried to visit this before /login (as I said above)
Please or to participate in this conversation.