MorphToSelect in Repeater (Mdue to MorphMany)
Hi all !
I'm trying to develop a planning tool where I've Tasks (or Milestones) and each may have dependencies (predecessors or successors) which are also Tasks (or Milestones).
To do that, both models extends an 'Activity' class where we can find the following relation :
public function predecessors() {
return $this->morphMany(Dependency::class, 'successor');
}
In the Dependency class, I retrieve the model by a morphTo relation :
public function successor()
{
return $this->morphTo();
}
So now I try to deals with a form Modal (I'm already in relationManager) using Repeater (for the MorphMany relation) then a MorphToSelect (for the morphOne). I tried several things but for me the most relevant would be :
Forms\Components\Repeater::make('predecessors')
->relationship()
->schema([
Forms\Components\MorphToSelect::make('successor')
->types([
Forms\Components\MorphToSelect\Type::make(Milestone::class)->titleColumnName('name'),
Forms\Components\MorphToSelect\Type::make(Task::class)->titleColumnName('name'),
]),
But this gives an error : Call to undefined method App\Models\Task::successor()
I thought I had understood that inside the repeater I was dealing with the relationship of the predecessors, not the record, but I was obviously wrong. Could someone point me in the right direction?
regards0 Replies