I have a model WorkflowStep with a Polyphormic relation to TransportWorkflowStep and TransformworkflowStep
My transportWorkflowStep has an other relation to client.
When I do this in my code:
/** @var TransportWorkflowStep $workflowStepEntity */
$workflowStepEntity = $workflowStep->entity;
try {
var_dump($workflowStepEntity->sourceClient);
} catch (\Exception $exception) {
dd($exception);
}
I get this error:
Call to undefined relationship [sourceClient] on model [App\TransformWorkflowStep].
First weird thing is that I am working with TransportWorkflowStep when I dd($workflowstep) so I don’t know why he’s complaining about TransformWorkflowStep
My WorkflowStep model:
public function entity(): MorphTo
{
return $this->morphTo();
}
My TransportWorkflowStep model:
public function workflowStep(): MorphOne
{
return $this->morphOne(WorkflowStep::class, 'entity');
}
public function sourceClient(): BelongsTo
{
return $this->belongsTo(Client::class, 'source_id', 'id');
}
public function destinationClient(): BelongsTo
{
return $this->belongsTo(Client::class, 'destination_id', 'id');
}
My TransformWorkflowStep model:
public function workflowStep(): MorphOne
{
return $this->morphOne(WorkflowStep::class, 'entity');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire