filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.08k stars 2.83k forks source link

Creating a new option in a modal not work with tenancy - createOptionForm #9176

Closed miguelurtado closed 11 months ago

miguelurtado commented 11 months ago

Package

filament/filament

Package Version

v3.0.80

Laravel Version

v10.28.0

Livewire Version

v3.0.10

PHP Version

PHP 8.2.11

Problem description

Creating a new option in a modal not work with tenancy - createOptionForm

Expected behavior

The team_id automatically added.

Steps to reproduce

Create on select field using createOptionForm. Exemple in repository DepartmentResource.

Reproduction repository

https://github.com/miguelurtado/filament_tenancy

Relevant log output

SQLSTATE[HY000]: General error: 1364 Field 'team_id' doesn't have a default value
danharrin commented 11 months ago
Screenshot 2023-10-19 at 10 21 36
zenati commented 11 months ago

@danharrin I have the same issue. But I don't understand how to handle it properly.

Since I use ComputerSoftware for counting, I need to scope it to the current tenant.

Tenant 1
(Model) Computer 1 (with tenant_id)
(Model) Software 1 (with tenant_id)
(Join table) ComputerSoftware (with tenant_id)
Tenant 2
(Model) Computer 2 (with tenant_id)
(Model) Software 2 (with tenant_id)
(Join table) ComputerSoftware (with tenant_id)

From my understanding in your last comment, this is not possible. Would that be possible with a hook that sets tenant_id before saving the ComputerSoftware record?

Thank you!

danharrin commented 11 months ago

It is possible, we just dont do it automatically.

createOptionAction(fn ($action) => $action->mutateFormDataUsing(function () {
    // set tenant in $data

    return $data;
}))