<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Miguel López</title>
    <description>The latest articles on Forem by Miguel López (@mlz).</description>
    <link>https://forem.com/mlz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1332603%2F4f53c8c3-0b37-45db-96c8-14748405d430.jpeg</url>
      <title>Forem: Miguel López</title>
      <link>https://forem.com/mlz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mlz"/>
    <language>en</language>
    <item>
      <title>Filament v3 - Multi-tenancy form component scoping</title>
      <dc:creator>Miguel López</dc:creator>
      <pubDate>Wed, 06 Mar 2024 17:01:08 +0000</pubDate>
      <link>https://forem.com/mlz/filament-v3-multi-tenancy-form-component-scoping-4ho8</link>
      <guid>https://forem.com/mlz/filament-v3-multi-tenancy-form-component-scoping-4ho8</guid>
      <description>&lt;h2&gt;
  
  
  Multi-Tenancy feature
&lt;/h2&gt;

&lt;p&gt;After following the &lt;a href="https://filamentphp.com/docs/3.x/panels/tenancy"&gt;documentation of Multi-Tenancy&lt;/a&gt; everything works well until I started to follow the &lt;a href="https://filamentphp.com/docs/3.x/panels/getting-started"&gt;demo project&lt;/a&gt; using the learned on the tenancy part :D&lt;/p&gt;

&lt;p&gt;All the forms were automagically scoped with the current tenancy value, but once I started to use the modals forms I started to got some errors like &lt;/p&gt;

&lt;p&gt;&lt;code&gt;SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "team_id" of relation "owners" violates not-null constraint DETAIL:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is because Filament does not currently provide this feature on some component forms as &lt;a href="https://filamentphp.com/docs/3.x/panels/tenancy#tenancy-security"&gt;we can read here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The solution for this, is use the &lt;code&gt;createOptionUsing&lt;/code&gt; method on the &lt;code&gt;Filament\Forms\Components\Select&lt;/code&gt; component as we can see in &lt;a href="https://filamentphp.com/docs/3.x/forms/fields/select#customizing-new-option-creation"&gt;the documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So I put this code instead:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;-&amp;gt;createOptionUsing(fn ($data) =&amp;gt; Filament::getTenant()-&amp;gt;owners()-&amp;gt;create($data)-&amp;gt;id)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And the tenant value was saved correctly :).&lt;/p&gt;

&lt;p&gt;All this wasn't my idea, I posted this issue as a bug on the github and I received this solution haha. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/filamentphp/filament/issues/11709"&gt;https://github.com/filamentphp/filament/issues/11709&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have shared this with you because if you encounter the same problem, I hope this explanation will help you.&lt;/p&gt;

</description>
      <category>filament</category>
      <category>laravel</category>
      <category>php</category>
    </item>
  </channel>
</rss>
