PHP code example of dalisoft / userstamps

1. Go to this page and download the library: Download dalisoft/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/ */

    

dalisoft / userstamps example snippets


Schema::create('mytable', function (Blueprint $table) {

    $table->userstamps();
});

Schema::create('mytable', function (Blueprint $table) {

    $table->unsignedInteger('created_by')->nullable();
    $table->unsignedInteger('updated_by')->nullable();
    $table->unsignedInteger('deleted_by')->nullable();
});

Schema::create('mytable', function (Blueprint $table) {

    $table->dropUserstamps();
});

use DaLiSoft\Userstamps\Userstamps;

class Foo extends Model {

    use Userstamps;
}

use DaLiSoft\Userstamps\Userstamps;

class Foo extends Model {

    use Userstamps;
    const CREATED_BY = 'alt_created_by';
    const UPDATED_BY = 'alt_updated_by';
    const DELETED_BY = 'alt_deleted_by';
    const DISPLAY_USER = 'email';
}

$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

$model->stopUserstamping(); // stops userstamps being maintained on the model
$model->startUserstamping(); // resumes userstamps being maintained on the model

$model->created_by_user; // creator username in the model
$model->updated_by_user; // editor username in the model
$model->deleted_by_user; // destroyer username in the model

$model->foos->each(function ($item) {
    $item->bar = 'x';
    $item->save();
});

$model->foos()->update([
    'bar' => 'x',
]);

$model->where('name', 'foo')->update([
    'name' => 'bar',
]);

$model->where('name', 'foo')->updateWithUserstamps([
    'name' => 'bar',
]);