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
Dennis Koch
Dennis Koch5mo ago
No idea without seeing any of the code
Alnuaimi
AlnuaimiOP5mo ago
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...
Dennis Koch
Dennis Koch5mo ago
What's your code that throws the error?
Alnuaimi
AlnuaimiOP5mo ago
just I want to add new method into one model insidel that
Dennis Koch
Dennis Koch5mo ago
Yes and how did you do that? Where is the error coming from?
Alnuaimi
AlnuaimiOP5mo ago
<?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()
Blackpig
Blackpig5mo ago
Where are you calling the method from? - are you importing the vendor file or your extended file there?
Dennis Koch
Dennis Koch5mo ago
@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
Alnuaimi
AlnuaimiOP5mo ago
this is the problem ,every thing inside vendor directory just I want add method as inside model RingleSoft\LaravelProcessApproval\Models\ProcessApprovalFlowStep
Dennis Koch
Dennis Koch5mo ago
Well, it doesn't work this way
Alnuaimi
AlnuaimiOP5mo ago
Is there another way?
Want results from more Discord servers?
Add your server