How to Fix 'Call to undefined method' Error in Inherited Laravel Model?
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?
11 Replies
No idea without seeing any of the code
I am using this https://github.com/ringlesoft/laravel-process-approval I want add method into one model
GitHub
GitHub - ringlesoft/laravel-process-approval: Laravel Process Appro...
Laravel Process Approval is a Laravel package that makes it easy to add approvals to your Laravel application. It allows you to define approval workflows for any model, and it provides a simple and...
What's your code that throws the error?
just I want to add new method into one model insidel that
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()
Where are you calling the method from? - are you importing the vendor file or your extended file there?
@Alnuaimi 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
this is the problem ,every thing inside vendor directory just I want add method as inside model RingleSoft\LaravelProcessApproval\Models\ProcessApprovalFlowStep
Well, it doesn't work this way
Is there another way?