Filament: Disable Dashboard and Auto-Redirect to URL After Login

Sometimes your Filament panel will not have a dashboard and will redirect your user to a specific page after logging in. But how is that done? Do you have to build a custom login page? No! There's a much easier way.


Single Panel Redirect

If you have just one panel in your filament application, you can implement the redirect as follows:

Create a new file app/Http/Responses/LoginResponse.php with the following contents:

namespace App\Http\Responses;
 
use App\Filament\Resources\OrderResource;
use Illuminate\Http\RedirectResponse;
use Livewire\Features\SupportRedirects\Redirector;
 
class LoginResponse extends \Filament\Http\Responses\Auth\LoginResponse
{
public function toResponse($request): RedirectResponse|Redirector
{
// Here, you can define which resource and which page you want to redirect to
return redirect()->to(OrderResource::getUrl('index'));
}
}

Then all we have to do is modify the Singleton:

app/Providers/AppServiceProvider.php

use Filament\Http\Responses\Auth\Contracts\LoginResponse;
use Illuminate\Support\ServiceProvider;
// ...
 
public function register(): void
{
$this->app->singleton(
LoginResponse::class,
\App\Http\Responses\LoginResponse::class
);
}

That's it! When you log in, the filament will attempt to return LoginResponse internally, but we just changed the implementation to our own, which redirects to the order resource.


Multiple Panel Redirect

You can implement the redirect per panel if you have multiple panels in your filament application! Here's how:

Create a new file app/Http/Responses/LoginResponse.php with the following contents:

use App\Filament\Customer\Resources\MyOrdersResource;
use App\Filament\Resources\OrderResource;
use Filament\Facades\Filament;
use Illuminate\Http\RedirectResponse;
use Livewire\Features\SupportRedirects\Redirector;
 
class LoginResponse extends \Filament\Http\Responses\Auth\LoginResponse
{
public function toResponse($request): RedirectResponse|Redirector
{
// You can use the Filament facade to get the current panel and check the ID
if (Filament::getCurrentPanel()->getId() === 'admin') {
return redirect()->to(OrderResource::getUrl('index'));
}
 
if (Filament::getCurrentPanel()->getId() === 'customer') {
return redirect()->to(MyOrdersResource::getUrl('index'));
}
 
return parent::toResponse($request);
}
}

Then all we have to do is modify the Singleton:

app/Providers/AppServiceProvider.php

use Filament\Http\Responses\Auth\Contracts\LoginResponse;
use Illuminate\Support\ServiceProvider;
// ...
 
public function register(): void
{
$this->app->singleton(
LoginResponse::class,
\App\Http\Responses\LoginResponse::class
);
}

That's it! Now each panel will redirect to a different resource after login.

avatar

Short and helpful, thanks!

👍 3

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 50 courses (910 lessons, total 46 h 42 min)
  • 69 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials