DEV Community

GAJALUXSAN
GAJALUXSAN

Posted on

Laravel Tip: Automatically Set created_by with Model Events

Want to track who created or updated a record in Laravel? Try this:

protected static function booted()
{
    static::creating(function ($model) {
        $model->created_by = auth()->id();
    });
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)