© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
Scott

How do you get the current tenant id?

I'd like to get the current team id (team = my tenant) when in a controller, e.g.

<?php

namespace App\Http\Controllers;

use App\Models\Team;
use Filament\Facades\Filament;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;

class AirtableOAuthController extends Controller
{
    public function connect(Request $request)
    {
        $tenant = Filament::getTenant(Team::class);
        dd($tenant);
    }
}
<?php

namespace App\Http\Controllers;

use App\Models\Team;
use Filament\Facades\Filament;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;

class AirtableOAuthController extends Controller
{
    public function connect(Request $request)
    {
        $tenant = Filament::getTenant(Team::class);
        dd($tenant);
    }
}


But it's returning "null" (also returns null if I just do
Filament::getTenant();
Filament::getTenant();
Solution
Had to go digging in the filament vendor package... Basically, you add an event listener to the setTenant function.

php artisan make:listener UpdateLatestTeamId --event=TenantSet
php artisan make:listener UpdateLatestTeamId --event=TenantSet


Then in your new file (e.g.
app/Listeners/UpdateLatestTeamId.php
app/Listeners/UpdateLatestTeamId.php
) you could put

<?php

namespace App\Listeners;

use Filament\Events\TenantSet;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class UpdateLatestTeamId
{
    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
        Log::info('UpdateLatestTeamId::__construct()');
    }

    /**
     * Handle the event.
     */
    public function handle(TenantSet $event): void
    {
        // get the user from the event
        $user = $event->getUser();

        // get the tenant (team) from the event
        $team = $event->getTenant();

        // update the user's latest_team_id
        $user->latest_team_id = $team->id;
        $user->save();
    }
}
<?php

namespace App\Listeners;

use Filament\Events\TenantSet;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class UpdateLatestTeamId
{
    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
        Log::info('UpdateLatestTeamId::__construct()');
    }

    /**
     * Handle the event.
     */
    public function handle(TenantSet $event): void
    {
        // get the user from the event
        $user = $event->getUser();

        // get the tenant (team) from the event
        $team = $event->getTenant();

        // update the user's latest_team_id
        $user->latest_team_id = $team->id;
        $user->save();
    }
}


And then you need to register your new listener in
app/Providers/EventServiceProvider.php
app/Providers/EventServiceProvider.php
like so

    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
        'Filament\Events\TenantSet' => [
            'App\Listeners\UpdateLatestTeamId',
        ],
    ];
    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
        'Filament\Events\TenantSet' => [
            'App\Listeners\UpdateLatestTeamId',
        ],
    ];
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

Get the active tenant id
FilamentFFilament / ❓┊help
2y ago
How to get current tenant in FilamentServiceProvider?
FilamentFFilament / ❓┊help
12mo ago
Accessing the current tenant
FilamentFFilament / ❓┊help
3y ago
How do i Get the current record in Select i want values except the current record id
FilamentFFilament / ❓┊help
2y ago