lundi 27 novembre 2017

Laravel mutual methods for many models

I added a method to one of my models:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Test extends Model
{
    public static function boot()
    {
        parent::boot();

        static::created(function ($model) {
            //log $model or maybe do something more complex here
        });
    }
}

And i wish to extend the same behaviour to many other models. Copy pasting this doesent seem like a good idea because if something changes i dont want to change it in different places. What is the best solution to write this only once and get the same behaviour to multiple models?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2hW3nYh
via IFTTT

Aucun commentaire:

Enregistrer un commentaire