I have a model where current_order_workflow_step is optional order_workflow_step is basially a join table to workflow_step, but has a few extra columns I want to define a relationship to get the current_workflow_step, but the trick is that the current_order_workflow_step isn't always set, so I'm not sure how is the best way to write it to allow for that. This is my attempt:
public function current_order_workflow_step()
{
return $this->belongsTo('OrderWorkflowStep','current_order_workflow_step_id');
}
public function current_workflow_step()
{
if($this->current_workflow_step_id)
{
return $this->current_order_workflow_step()->with('workflow_step')->first()->workflow_step;
}
else
{
return $this->current_order_workflow_step();
}
}
That seems to be working, but I'm not sure if there is a way to do this more properly?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community