<?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');
}
}