Skip to content

sansanlabs/laravel-userstamps

Repository files navigation

Laravel Userstamps

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require sansanlabs/laravel-userstamps

You can publish the config file with:

php artisan vendor:publish --tag="userstamps-config"

This is the contents of the published config file:

return [
  /*
   * Specify the column type used in the schema for the account ID
   *
   * Options: increments, bigIncrements, uuid, ulid
   * Default: bigIncrements
   */
  "users_table_id_column_type" => "bigIncrements",

  /*
   * Specify the column name used as the foreign key reference for the account ID. Make sure all user tables have an ID column name that matches the one you define below.
   */
  "users_table_id_column_name" => "id",

  /*
   * Specify the column that stores the ID of the user who initially created the entry
   */
  "created_by_column" => "created_by",

  /*
   * Specify the column that holds the ID of the user who last updated the entry
   */
  "updated_by_column" => "updated_by",

  /*
   * Specify the column that contains the ID of the user who removed the entry
   */
  "deleted_by_column" => "deleted_by",

  /*
   * Indicate whether to include soft-deleted records in queries
   */
  "with_trashed" => false,
];

Usage

Add the macro to your migration of your model

public function up(){
    Schema::create('table_name', function (Blueprint $table) {
        ...
        $table->userstamps();
        $table->softUserstamps();
    });
}

Add the macro to your existing table

public function up()
{
    Schema::table('table_name', function($table) {
        ...
        $table->userstamps();
        $table->softUserstamps();
    });
}


public function down()
{
    Schema::table('table_name', function($table) {
        $table->dropUserstamps();
        $table->dropSoftUserstamps();
    });
}

Add the Trait to your model

use SanSanLabs\UserStamps\Concerns\HasUserstamps;

class Example extends Model {
  use HasUserstamps;
}

There will be methods available to retrieve the user object which performs the action for creating, updating or deleting

$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

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.