Bagisto: Override core model not in effect

Created on 19 Sep 2019  路  7Comments  路  Source: bagisto/bagisto

1) Created app/Http/Customer.php

<?php

namespace App\Http;

use Webkul\Customer\Models\Customer as CustomerBaseModel;

class Customer extends CustomerBaseModel
{
    /**
     * Get the customer full name.
     */
    public function getNameAttribute() {
        return 'MY CUSTOM NAME';
    }
}

2) In app/Providers/AppServiceProvider.php added

    public function boot()
    {
        $this->app->concord->registerModel(
            \Webkul\Customer\Contracts\Customer::class, \App\Http\Customer::class
        );

        Schema::defaultStringLength(191);
    }

Laravel doesn't give any error my any place I do dd($customer) it gives me old Webkul\Customer\Models\Customer model.

As on screenshot customer has still default name

image

Help Wanted

Most helpful comment

Still don't understand how to override the core model. I'm trying to add a trait to bagisto's customer model and couldn't figure it out for 2 days.

All 7 comments

@jyoti-webkul Anyone? It has been reported by other people

Hi @accountmine

Your whole code is correct instead of dumping whole customer, try to dd($customer->name), because you have created Accessor for name.

For more detail, please go through with this article - https://laravel.com/docs/5.8/eloquent-mutators#defining-an-accessor

Thanks

@accountmine You need to have a default ModuleServiceProvider dedicated to models that you making in App namespace.
And those models too should implement their contracts as in packages and type hint their proxy class with them.

Please go through with the directory structure of Customer package and specifically models, contracts and the module service provider.

Note: The module service provider you will make for your models inside App namespace should also be in configuration of concord.php also.

That is all, if you face any issue we won't mind ever to help.

Regards,
Prashant.

@prashant-webkul Would you mind update documentation with a working example.

It means overridden Modal will be available only in my new module? Not thought default webkul endpoints?

@accountmine yes, the model will be override for your new package. Also, we will soon update the documentation with a working example.

Thanks

Still don't understand how to override the core model. I'm trying to add a trait to bagisto's customer model and couldn't figure it out for 2 days.

Same here. I'm following the Bagisto docs: https://devdocs.bagisto.com/override-core-model.html and it is not working. Some help?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

farshadff picture farshadff  路  6Comments

MostafaAttia picture MostafaAttia  路  4Comments

nguyenthanhtuanIT picture nguyenthanhtuanIT  路  4Comments

alkhachatryan picture alkhachatryan  路  7Comments

farshadff picture farshadff  路  4Comments