Package Data | |
---|---|
Maintainer Username: | Arkitecht |
Maintainer Contact: | aaron@arkitech.net (Aaron Rubin) |
Package Create Date: | 2015-08-31 |
Package Last Update: | 2024-07-08 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-23 15:02:05 |
Package Statistics | |
---|---|
Total Downloads: | 10,615 |
Monthly Downloads: | 21 |
Daily Downloads: | 0 |
Total Stars: | 4 |
Total Watchers: | 3 |
Total Forks: | 1 |
Total Open Issues: | 0 |
Easily attribute the creator / last updater of a model in your database.
Designed to work like (and alongside) $table->timestamps() in your Laravel migrations, Attributions introduces $table->attributions(). This will add creator_id and updater_id columns to your table to track the user that created and updated the model respectively. By default this uses the Laravel 5.1 predefined users table, but can be customized to reference any table and key combination.
You can install the package most easily through composer
composer require arkitecht/laravel-attributions
Once this operation is complete, you can update the Schema Facade to point to our drop-in replacement, which uses our Blueprint extension class to add the attributions.
~~'Schema' => Illuminate\Support\Facades\Schema::class,~~
'Schema' => Arkitecht\Attributions\Facades\Schema::class,
You can also manually use the attributions builder, without overwriting the Facade like so:
use Arkitecht\Attributions\Database\Schema\Blueprint;
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$schema = DB::getSchemaBuilder();
$schema->blueprintResolver(function($table, $callback) {
return new Blueprint($table, $callback);
});
$schema->create('tests', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->attributions();
});
}
To have your migration add the attribution columns, just call the Blueprint::attributions method.
class CreateTestsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tests', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->attributions();
});
}
...
}
You can also have it reference an alternate table (from users) or key (from id).
class CreateTestsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tests', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->attributions('employees','employee_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('tests');
}
}
To have the creator and updater automagically updated when a model is created and updated, just use the Attributions trait in your model.
<?php
namespace App;
use Arkitecht\Attributions\Traits\Attributions;
use Illuminate\Database\Eloquent\Model;
class Test extends Model
{
use Attributions;
}
?>