ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Ability to get event name which fires in Eloquent booted method

Open foremtehan opened this issue 3 years ago • 1 comments

Looking for a way to get event name which fires in booted method in string.

Instead of :

protected static function booted()
{
    static::updating(function (self $m) {
        //same thing
    });

    static::updated(function (self $m) {
        //same thing
    });
}

I wish i could able to do this:

if (in_array($event = static::getEventName(), ['updating', 'updated'])) {
    static::$event(function (self $m) {
        //
    });
}

foremtehan avatar Jun 30 '21 17:06 foremtehan

this package is out of date but you can do like this https://github.com/RMoorePHP/change-recorder/blob/4dac6bc5771507e4f1bd6277d2a99d84da555275/src/RecordsChanges.php#L9-L13

rs-sliske avatar Jul 01 '21 12:07 rs-sliske