laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

[Proposal][Migrations] User stamps #1552

Open ghost opened 5 years ago

ghost commented 5 years ago

Similar to $table->timestamps(), the migrations would benefit from having $table->userstamps() that would add the following columns to the table:

- user_created
- user_updated
- user_deleted

And also having the const inside eloquent models for changing the user stamps configuration:

public $userstamps = true;

const USER_CREATED = "user_created";
const USER_UPDATED = "user_updated";
const USER_DELETED = "user_deleted";
mfn commented 5 years ago

Can you clarify how they are supposed to work?

tomschlick commented 5 years ago

In my experience this is best left to a change log table as most of the time you'd want to know what exactly each user changed.

Sladewill commented 5 years ago

Package like https://github.com/owen-it/laravel-auditing does that and more.

ghost commented 5 years ago

@tomschlick, just a simple implementation just like the updated_at, most of the projects won't have it necessary to know what changed in the model.

ghost commented 5 years ago

@Sladewill, I was looking into a more simple implementation that could be used in every project of small or medium scope. Every project that I work I have to do that by hand, every time I use timestamps I also use this.

ghost commented 5 years ago

@mfn, just a more complete implementation of the timestamp, this is just basic for "everyday use". To make easier to track who used that table. As @tomschlick said, this could be evolved to make possible to know what exactly the user changed, but in most of the cases (small projects), just the basic is enough.

mfn commented 5 years ago

I understand. To me, the current proposal doesn't feel right being included by default.

I believe a) the majority will not need this and b) the ones who need something like this, need a more complete solution (as suggested by others).

Arkitecht commented 5 years ago

I built a package a while back that does just this: https://github.com/arkitecht/laravel-attributions If there is interest I can update it / polish it some