Can't hydrate single edit/view page select field with M:M relationship

Laravel/Filament newbie. Any help would be much appreciated 🙂

I have data stored in M:M table
primary_id company_id prefecture_id timestamps
183    1    3    2023-11-09 08:33:37    2023-11-09 08:33:37
184    1    5    2023-11-09 08:33:37    2023-11-09 08:33:37
185    1    7    2023-11-09 08:33:37    2023-11-09 08:33:37

Trying to hydrate it in custom page CompanyRegions.php
namespace App\Filament\Pages;
class CompanyRegions extends Page implements HasForms
{
    //
    public function mount(): void {
        $tenant = Filament::getTenant();
        $companyID = $tenant->id;

        $companyPrefectures = auth()->user()->companies->find($companyID)->prefectures;
    
        $existing_prefectures = [];
        foreach($companyPrefectures as $prefecture) {
            Log::info($prefecture->prefecture_ja);

            array_push($existing_prefectures, $prefecture->id);
        }

        $companyCities = auth()->user()->companies->find($companyID)->cities;
        
        $this->form->fill($existing_prefectures);

}

But I end up passing fill($existing_prefectures) this:
    +data: array:4 [▼
      0 => 3
      1 => 4
      2 => 6
      "prefecture_id" => []
    ]
  }


doing fill($companyPrefectures->attributesToArray()) also does not work (method does not exist error)

I feel like I'm almost there but don't understand something important. Or maybe https://livewire.laravel.com/docs/lifecycle-hooks#mount only accepts non-complex data, I don't know. fill($data) works just fine for me for Models that have simple input fields.
Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
Was this page helpful?