You can install this package via composer:
composer require tobymaxham/laravel-helper
Track if user created, updated or deleted a Model
. You have to add these attributes to you database table.
By default the fields created_by
, updated_by
and deleted_by
fields will be used.
namespace App;
use TobyMaxham\Helper\Models\Logs\ChangeByUser;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use ChangeByUser;
}
You could also turn off tracking by returning false
to the attribute fetching methods:
public function getCreatedByColumn()
{
return false;
}
With my MigrationHelper
you can automatically add the fields to you migrations file:
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('content');
MigrationHelper::addCreatedByUser($table);
$table->timestamps();
});
}
Or you can create all three fields at once by calling MigrationHelper::addChangedByUserFields($table)
.
Please see CHANGELOG for more information what has changed recently.
The MIT License (MIT). Please see License File for more information.