Laravel Userstamps provides an Eloquent trait that automatically maintains created_by and updated_by columns on your model, populated by the currently authenticated user in your application. Your model must include a created_by and updated_by column, defaulting to null.
use Wildside\Userstamps\Userstamps; class Foo extends Model { use Userstamps; const CREATED_BY = 'alt_created_by'; const UPDATED_BY = 'alt_updated_by'; const DELETED_BY = 'alt_deleted_by'; }
$model->creator; // the user who created the model $model->editor; // the user who last updated the model $model->destroyer; // the user who deleted the model
In this example, model relations are updated via Eloquent and userstamps will be maintained: $model->foos->each(function ($item) { $item->bar = 'x'; $item->save(); }); However, in this example, model relations are bulk updated and bypass Eloquent.