Change $workflow->statuses()->whereIn() to $workflow->statuses->whereIn()
Nov 9, 2018
15
Level 2
Eloquent Method Does Not Exist
So I am trying to call a method from my eloquent model however it tells me it doesn't exist. Looking to see if some body could tell me what I am doing wrong.
the issue is with the mehtod statuses()
here is the controller
public function updateWorkflowStatuses(Request $request)
{
// validate form data
$validated = $request->validate([
'id' => 'required|integer',
'statuses' => 'required|array',
]);
$workflow = Workflow::where('id', $validated['id'])->get();
$statuses = $validated['statuses'];
$workflow->statuses()->whereIn('workflow_id', $validated['id'])->delete();
foreach($statuses as $status){
$workflow->statuses()->create([
'status' => $statuses['status'],
'order' => $statuses['order']
]);
};
return response('Update Succesful', 200);
}
here is the model
class Workflow extends Model
{
protected $fillable = [
'workflow'
];
public function statuses()
{
return $this->hasMany('App\Status');
}
public function engagements()
{
return $this->hasMany('App\Engagement');
}
}
Level 60
$workflow = Workflow::where('id', $validated['id'])->firstOrFail();
Try to use firstOrFail(), instead of get()
Please or to participate in this conversation.