© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•15mo ago•
16 replies
mohdaftab

Show 404 if tenant doesn't exists

Hello everyone,

I am using subdomains for multi-tenancy in my Filamentphp v3 project.
The login pages for subdomains are like company-1.domain.com/dashboard/login
company-2.domain.com/dashboard/login

both company-1 and company-2 are registered as a tenant and the login page works good, but when I try to access company-3 subdomain which isn't registered, I still see the login page.
Is there a way to show 404 page if the tenant status is not active or it doesn't exist.

Thank you so much.
Solution
public function handle(Request $request, Closure $next): Response
    {
        if (!Auth::check()) {
            $slug = explode('.', $request->getHost())[0]; // Extract the subdomain

            // Check if the tenant exists
            if (!Company::where('slug', $slug)->exists()) {
                throw new NotFoundHttpException(); // Show 404 page if not found
            }

            return $next($request);
        }

        return $next($request);
    }
public function handle(Request $request, Closure $next): Response
    {
        if (!Auth::check()) {
            $slug = explode('.', $request->getHost())[0]; // Extract the subdomain

            // Check if the tenant exists
            if (!Company::where('slug', $slug)->exists()) {
                throw new NotFoundHttpException(); // Show 404 page if not found
            }

            return $next($request);
        }

        return $next($request);
    }
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Show Icon tenant If user Is_admin
FilamentFFilament / ❓┊help
3y ago
Tenant panel gives 404
FilamentFFilament / ❓┊help
3y ago
ChartJS DataLabels doesn't show
FilamentFFilament / ❓┊help
4mo ago
Relationship Manager doesn't show
FilamentFFilament / ❓┊help
3y ago