How to overwrite an vendor class

600 views Asked by At

How can i overwrite a vendor class? I'm using Laravel Spark and i wanna have Uuid for all models. Due Spark manage some models inside the package and i don't see a possibility to use my own model for Notifications etc. i would like to overwrite the base Model class from Illuminate\Database\Eloquent\Model, so i could include there my uuid trait.

I tried over the ServiceProvider with:

public function boot()
{
    //
    $this->app->bind('Illuminate\Database\Eloquent\Model', 'App\Models\Model');
}

But it didn't worked.

Is it possible or maybe exist a better way?

Thanks for any help.

1

There are 1 answers

3
Saumini Navaratnam On

Create a custom model class which will extend the eloquent model.

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CustomModel extends Model {
    // Your implementation
}

And then rest of the models you extend your custom model.

class Test extends CustomModel {
}