© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•4mo ago•
2 replies
Simone

Testing tenant-aware resources in v4

What I am trying to do:
I'm trying to test the creation of a tenant-aware resource. I've just updated my application from version 3 following the upgrade guide.
The tests were working fine before the update, but now I'm getting an error related to a missing tenant ID in insert queries.

What I did:
I've read the new information about multi-tenancy (https://filamentphp.com/docs/4.x/users/tenancy#tenancy-security). I now understand that there is a middleware that automatically manages queries, but, since I'm coming from version 3, my models are manually managed to the tenant.
This shouldn't be a problem, because I've checked the code and seen that if the scope is already applied, nothing should happen.
I've got no issues with browser requests, though, so I think there is probably something missing or wrong in the instructions.

My issue/the error:
NOT NULL constraint failed: customers.tenant_id ...
NOT NULL constraint failed: customers.tenant_id ...


Code:
it('can create a customer', function () {
    $customer = Customer::factory()->make();

    livewire(CreateCustomer::class)
        ->fillForm([
            'type' => $customer->type,
            'first_name' => $customer->first_name,
            'last_name' => $customer->last_name,
        ])
        ->call('create')
        ->assertHasNoFormErrors();

    assertDatabaseHas('customers', [
        'type' => $customer->type,
        'first_name' => $customer->first_name,
        'last_name' => $customer->last_name,
    ]);
});
it('can create a customer', function () {
    $customer = Customer::factory()->make();

    livewire(CreateCustomer::class)
        ->fillForm([
            'type' => $customer->type,
            'first_name' => $customer->first_name,
            'last_name' => $customer->last_name,
        ])
        ->call('create')
        ->assertHasNoFormErrors();

    assertDatabaseHas('customers', [
        'type' => $customer->type,
        'first_name' => $customer->first_name,
        'last_name' => $customer->last_name,
    ]);
});
Multi-tenancy - Users - Filament
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Make page tenant aware
FilamentFFilament / ❓┊help
2y ago
Global resources in tenant
FilamentFFilament / ❓┊help
3y ago
V4 Nested Resources
FilamentFFilament / ❓┊help
9mo ago
Testing page footer actions in v4
FilamentFFilament / ❓┊help
6mo ago