CreateOptionUsing Exception

My code look as follow also when createOptionUsing is executed everything works pefectly but when I return the newly created id of my tags, it throw this exception (screenshot)
public function form(Form $form): Form
{
return $form
->schema([
Select::make('tag_id')
->label('')
->multiple()
->options(function (callable $get) {
return $this->team->tags()->pluck('name', 'id');
})
->model(Team::class)
->relationship('tags', 'name')
->createOptionForm([
TextInput::make('name')
->required(),
ColorPicker::make('color')
->hex()
->default('#000000')
])
->createOptionUsing(function (array $data): int {
return auth()->user()->currentTeam->tags()->create($data)->getKey();
})
->searchable()
]);
}
public function form(Form $form): Form
{
return $form
->schema([
Select::make('tag_id')
->label('')
->multiple()
->options(function (callable $get) {
return $this->team->tags()->pluck('name', 'id');
})
->model(Team::class)
->relationship('tags', 'name')
->createOptionForm([
TextInput::make('name')
->required(),
ColorPicker::make('color')
->hex()
->default('#000000')
])
->createOptionUsing(function (array $data): int {
return auth()->user()->currentTeam->tags()->create($data)->getKey();
})
->searchable()
]);
}
Thanks
No description
8 Replies
Dennis Koch
Dennis Koch6mo ago
Please share the Flare error as mentioned in #✅┊rules
Clement
ClementOP6mo ago
Flare
Only arrays and Traversables can be unpacked - The error occurred at http://localhost:8000/teams/1
Dennis Koch
Dennis Koch6mo ago
Is this admin panel or form builder?
Clement
ClementOP6mo ago
Form Builder
<?php

namespace App\Livewire\Organisation;

use App\Models\Team;
use Filament\Forms\Components\ColorPicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Livewire\Component;

class TagManager extends Component implements HasForms
{
use InteractsWithForms;

public Team $team;


public function form(Form $form): Form
{
return $form
->schema([
Select::make('tag')
->multiple()
->options(function (callable $get) {
return $this->team->tags()->pluck('name', 'id')->toArray();
})
->model(Team::class)
->relationship('tags', 'name')
->createOptionForm([
TextInput::make('name')
->required(),
ColorPicker::make('color')
->hex()
->default('#000000')
])
->createOptionUsing(function (array $data) {
return auth()->user()->currentTeam->tags()->create($data)->getKey();
})
]);
}

public function mount(): void
{
$this->form->fill([
'tag' => $this->team->tags->pluck('id')->toArray(),
]);
}

public function render()
{
return view('components.Organisation.tag-manager');
}
}
<?php

namespace App\Livewire\Organisation;

use App\Models\Team;
use Filament\Forms\Components\ColorPicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Livewire\Component;

class TagManager extends Component implements HasForms
{
use InteractsWithForms;

public Team $team;


public function form(Form $form): Form
{
return $form
->schema([
Select::make('tag')
->multiple()
->options(function (callable $get) {
return $this->team->tags()->pluck('name', 'id')->toArray();
})
->model(Team::class)
->relationship('tags', 'name')
->createOptionForm([
TextInput::make('name')
->required(),
ColorPicker::make('color')
->hex()
->default('#000000')
])
->createOptionUsing(function (array $data) {
return auth()->user()->currentTeam->tags()->create($data)->getKey();
})
]);
}

public function mount(): void
{
$this->form->fill([
'tag' => $this->team->tags->pluck('id')->toArray(),
]);
}

public function render()
{
return view('components.Organisation.tag-manager');
}
}
Dennis Koch
Dennis Koch6mo ago
Not sure how to properly use fill with prefilled data but I guess you should pass an empty array for tag_id
Clement
ClementOP6mo ago
Yes it was for my previous test I set it to : $this->form->fill([]);
Dennis Koch
Dennis Koch6mo ago
Don’t give an empty array as param. Just without the param.
Clement
ClementOP6mo ago
Okay I also have tried without multiple, it works perfectly, but when I had multiple() it does not works anymore on creation process I have reupdated the source code on my last comment Resolved the problem came from JS part where they don't know what was tag
Want results from more Discord servers?
Add your server