Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

devhoussam123's avatar

Restricted access to multi tenancy features based on registration status

Understanding the Problem:

  • Users with "individual" registration status are redirected to the tenant registration page RegisterTenant which they shouldn't have access to.

  • I want to prevent this redirection and redirect them to their appropriate dashboard.

What I did:

  • I modify the handleRegistration() to:
  • Check the user's registration status before creating a tenant.
  • If individual redirect them to the dashboard using return redirect()->route('filament.app.pages.dashboard');.
  • If team_owner proceed with tenant creation and user attachment.

The code does not work as expected I still get access to filament.app.tenant.registration even my registration status is individual

My Current Codes:

2014_10_12_000000_create_users_table.php

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            ...
            $table->string('registration_status')->default('individual');
            ...
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
    }
};

app/Models/User.php

protected $fillable = [
    'registration_status',
];

app/Filament/App/Pages/Tenancy/RegisterTenant.php

<?php

namespace App\Filament\App\Pages\Tenancy;

use App\Models\Tenant;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Tenancy\RegisterTenant as BaseRegisterTenant;

class RegisterTenant extends BaseRegisterTenant
{
    protected static string $view = 'filament.app.pages.tenancy.register-tenant';

    public static function getLabel(): string
    {
        return __('Register Team');
    }

    public function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput::make('name')
                    ->required(),

                TextInput::make('slug')
                    ->required(),
            ]);
    }

    protected function handleRegistration(array $data): Tenant
    {
        $user = auth()->user();

        if ($user && $user->registration_status === 'team_owner') {
            $tenant = Tenant::create($data);

            $tenant->users()->attach($user);

            return $tenant;
        } else {
            return redirect()->route('filament.app.pages.dashboard');
        }
    }
}
0 likes
0 replies

Please or to participate in this conversation.