1

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.

mastercheef85
  • 2,109
  • 3
  • 18
  • 25
  • When you say `i don't see a possibility to use my own model for Notifications etc. i would like to overwrite the base Model class`... You should explain why? – prateekkathal Dec 24 '16 at 23:41
  • because the notification model is from spark package. so i can not adjust or overwrite ist (or don't know how) cause it's inside the package – mastercheef85 Dec 26 '16 at 11:02

1 Answers1

0

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 {
}
Saumini Navaratnam
  • 8,439
  • 3
  • 42
  • 70
  • The Notification Model and as well the others like User etc. are already extended fron the base model. – mastercheef85 Dec 24 '16 at 12:28
  • @mastercheef85 I understand your concern. I found following https://medium.com/@steveazz/setting-up-uuids-in-laravel-5-552412db2088#.74yoc66t5 online. Did you check this? – Saumini Navaratnam Dec 24 '16 at 13:04
  • thanks but yes i know it. the problem is not the uuid itself and using it on a model, the problem is that the vendor spark package. which has the notification and other models, use the default eloquent model from the framework. i can not alter the vendor models, so i wanna overwrite the default eloquent model to use the trait there that automatically all models are extended with. – mastercheef85 Dec 26 '16 at 10:32