sandbox-dev/laravel-userstamps

Laravel user stamps package

2.0.0 2024-04-29 10:55 UTC

This package is auto-updated.

Last update: 2024-04-29 10:57:16 UTC


README

This package requires PHP 7.2 and Laravel 5.6 or higher. Install the package by running the following command in your console;

composer require sandbox-dev/laravel-userstamps

You can publish the config file with:

php artisan vendor:publish --provider="Sandbox\UserStamps\UserStampsServiceProvider" --tag="config"

This is the contents of the published config file:

return [

    /*
     * Define the table which is used in the database to retrieve the users
     */

    'users_table' => 'users',
    
    /*
     * Define the table column type which is used in the table schema for
     * the id of the user
     *
     * Options: increments, bigIncrements, uuid
     * Default: bigIncrements
     */

    'users_table_column_type' => 'bigIncrements',

    /*
     * Define the name of the column which is used in the foreign key reference
     * to the id of the user
     */

    'users_table_column_id_name' => 'id',
    
    /*
     * Define the mmodel which is used for the relationships on your models
     */
    
    'users_model' => \App\Models\User::class,
    
    /*
     * Define the column which is used in the database to save the user's id
     * which created the model.
     */

    'created_by_column' => 'created_by',

    /*
     * Define the column which is used in the database to save the user's id
     * which updated the model.
     */

    'updated_by_column' => 'updated_by',

    /*
     * Define the column which is used in the database to save the user's id
     * which deleted the model.
     */

    'deleted_by_column' => 'deleted_by',

];

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 Trait to your model

use Sandbox\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->author; // the user who created the model
$model->editor; // the user who last updated the model
$model->destroyer; // the user who deleted the model