Updated 9 August 2022
To understand the concept of overriding first we need to understand How overriding works. Method Overriding is an OOPs concept. When a child class method overrides the parent class method of the same name, parameters, and return type, it is termed a method overriding
As you can see below screenshot method is already defined in Model class we want this method to override in our custom module. So follow the given steps
Use function registerModel() in customModule Service Provider as illustrated in the below code
1 2 3 4 5 6 7 8 9 10 11 12 |
/** * Bootstrap any application services. * * @return void */ public function boot() { $this->app->concord->registerModel( \Webkul\Customer\Models\Customer::class, \Webkul\Custom\Http\CustomCustomer::class ); } |
Now create a new class in the customModule in which you will define the method to override make sure to use the method name same as originally defined and remember to extend or implement the Model class as illustrated in the below code
1 2 3 4 5 6 7 8 9 |
/** * Overriden the Function * * @return string */ public function overrideFunction() { return "Overriden the Fuction"; } |
Run the given command
1 |
php artisan optimize |
So, that was much about the article “ How to Override Model Functions in Bagisto ”. Also for any queries or doubts reach out to us at [email protected]. You can also raise a ticket at our HelpDesk System.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.