mardi 23 juillet 2019

Should I register a model observer in a service provider or in Model?

There are 2 ways to register a model observer -

Approach 1: AppServiceProvider

 public function boot()
 {
     CourseTag::observe(CourseTagObserver::class);
 }

Approach 2: Model itself

 public function tags()
 {
     return $this->belongsTo(Tag::class, 'tag_id', 'id');
 }

I am not sure when to use approach 1 and when to use approach 2 ??



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire