Eloquent Method Does Not Exist

Posted 3 months ago by boldstar

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');
    }
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.