PHP code example of turahe / laravel-userstamps

1. Go to this page and download the library: Download turahe/laravel-userstamps library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

turahe / laravel-userstamps example snippets


use Turahe\UserStamps\Concerns\HasUserStamps;

class Post extends Model
{
    use HasUserStamps;
}

use Turahe\UserStamps\Concerns\HasCustomUserStamps;

class Post extends Model
{
    use HasCustomUserStamps;
    
    protected $userstampsConfig = [
        'columns' => [
            'created_by' => [
                'type' => 'uuid',
                'index' => true,
                'comment' => 'User who created this post'
            ],
            'updated_by' => [
                'type' => 'uuid',
                'nullable' => false
            ]
        ]
    ];
}

Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->userstamps();      // Adds created_by and updated_by
    $table->softUserstamps();  // Adds deleted_by
    $table->timestamps();
    $table->softDeletes();
});

return [
    'users_table' => 'users',
    'users_table_column_type' => 'bigIncrements',
    'users_table_column_id_name' => 'id',
    'users_model' => env('AUTH_MODEL', 'App\User'),
    
    // Legacy column names (backward compatible)
    'created_by_column' => 'created_by',
    'updated_by_column' => 'updated_by',
    'deleted_by_column' => 'deleted_by',
    
    // Enhanced column configuration
    'columns' => [
        'created_by' => [
            'name' => 'created_by',
            'type' => null,                   // Auto-detect
            'nullable' => true,
            'index' => true,
            'foreign_key' => true,
            'on_delete' => 'set null',
            'comment' => 'User who created this record'
        ],
        'updated_by' => [
            'name' => 'updated_by',
            'type' => null,
            'nullable' => true,
            'index' => true,
            'foreign_key' => true,
            'on_delete' => 'set null',
            'comment' => 'User who last updated this record'
        ],
        'deleted_by' => [
            'name' => 'deleted_by',
            'type' => null,
            'nullable' => true,
            'index' => true,
            'foreign_key' => true,
            'on_delete' => 'set null',
            'comment' => 'User who deleted this record'
        ]
    ]
];
bash
php artisan vendor:publish --provider="Turahe\UserStamps\UserStampsServiceProvider" --tag="config"