#How to Fix 'Call to undefined method' Error in Inherited Laravel Model?

13 messages · Page 1 of 1 (latest)

modern stream
#

I have created a new model in Laravel that extends a model from the vendor directory and added a new method (getNextApprovers) to the new model. However, when calling this method, I receive a Call to undefined method error. I have tried using __call and Traits, but the issue persists. How can I resolve this issue and ensure that the method works correctly in the new model?

muted robinBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

sharp acorn
#

No idea without seeing any of the code

modern stream
sharp acorn
#

What's your code that throws the error?

modern stream
sharp acorn
#

Yes and how did you do that? Where is the error coming from?

modern stream
# sharp acorn Yes and how did you do that? Where is the error coming from?

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use RingleSoft\LaravelProcessApproval\Models\ProcessApprovalFlowStep as BaseProcessApprovalFlowStep;

class ProcessApprovalFlowStep extends BaseProcessApprovalFlowStep
{
use HasFactory;

public function getNextApprovers(): \Illuminate\Database\Eloquent\Collection
{
    $nextStep = self::where('process_approval_flow_id', $this->processApprovalFlow->id)
        ->where('order', '>', $this->order)
        ->orderBy('order')
        ->first();

    if ($nextStep) {
        return $nextStep->role->users()->get();
    }

    return collect();
}

}

this is error
Call to undefined method RingleSoft\LaravelProcessApproval\Models\ProcessApprovalFlowStep::getNextApprovers()

proud girder
#

Where are you calling the method from? - are you importing the vendor file or your extended file there?

sharp acorn
#

@modern stream Please use code formatting as mentioned #✅┊rules. You are here long enough now to know this

#

You aren't calling your model but the parent model directly: RingleSoft\LaravelProcessApproval\Models\ProcessApprovalFlowStep

modern stream
sharp acorn
#

Well, it doesn't work this way