robjbrain / laravel-user-timestamps
Drop in replacements for UserTimestamps and SoftDeletes to also store the authenticated user id.
Installs: 128
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/robjbrain/laravel-user-timestamps
Requires
- php: >7.1.0
This package is auto-updated.
Last update: 2025-10-23 16:06:06 UTC
README
This is a drop in replacement for HasTimestamps trait in Laravel. It will add the additional fields. created_by_id and updated_by_id of the user that performed the operation.
It also supports polymorphic relationship which will add created_by_type and updated_by_type fields.
It also has support for SoftDeletes replacing Laravel's built in SoftDeletes trait to include deleted_by_id for the user who performed the soft delete.
Installation
You can install the package via composer:
composer require robjbrain/laravel-user-timestamps
Usage
Add the CacheMutationsTrait trait to a model you like to cache the mutations of.
use Robjbrain\LaravelUserTimestamps\HasUserTimestamps; use Robjbrain\LaravelUserTimestamps\UserSoftDeletes; class YourEloquentModel extends Model { use HasUserTimestamps; use UserSoftDeletes; // This will behave the same UserTimestamps public $timestamps = true; // This will utilise the updated_by_id and created_by_id fields public $userTimestamps = true; // This will utilise the updated_by_type and created_by_type fields public $polymorphicTimestamps = true; // This will utilise the deleted_by_id field public $userSoftDeletes = true; // This will utilise the deleted_by_type field public $polymorphicSoftDeletes = true; }
If you are using $polymorphicTimestamps you don't need to set $userTimestamps or $timestamps to true.
If you are using $userTimestamps you do not need to set $timestamps to true.