F
Filament15mo ago
Vp

call to member function on null in select with relationship

What should be the error here, my code
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Tabs::make('Label')
->tabs([
Forms\Components\Tabs\Tab::make('Personal details')
->schema([
Forms\Components\Grid::make()
->schema([
Forms\Components\Select::make('languages.name')
->label('Languages')
->required()
->multiple()
->relationship(name: 'languages', titleAttribute: 'name')
->searchable()
->preload(),
]),
]),
]),
]);
}

// relationship
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class);
}

// blade.php
{{ $this->form }}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Tabs::make('Label')
->tabs([
Forms\Components\Tabs\Tab::make('Personal details')
->schema([
Forms\Components\Grid::make()
->schema([
Forms\Components\Select::make('languages.name')
->label('Languages')
->required()
->multiple()
->relationship(name: 'languages', titleAttribute: 'name')
->searchable()
->preload(),
]),
]),
]),
]);
}

// relationship
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class);
}

// blade.php
{{ $this->form }}
I also put $this->form->fill(); in mount()
7 Replies
Vp
VpOP15mo ago
Error
No description
Dennis Koch
Dennis Koch15mo ago
You didn't provide a model, right?
Vp
VpOP15mo ago
wdym? I have this like below
public $candidate;

public function mount(): void
{
$this->candidate = Candidate::whereUserId(auth()->id())->first();

$this->form->fill();
}
public $candidate;

public function mount(): void
{
$this->candidate = Candidate::whereUserId(auth()->id())->first();

$this->form->fill();
}
Vp
VpOP15mo ago
I've added but still same error, this only happens on select with relationship.. but options is working
protected function getFormModel(): Model|string|null
{
return $this->candidate;
}
protected function getFormModel(): Model|string|null
{
return $this->candidate;
}
Vp
VpOP15mo ago
Still not working, maybe my approach is bad.. I'll check more
Want results from more Discord servers?
Add your server