PHP code example of wildside / userstamps

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

    

wildside / userstamps example snippets


$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();

use Wildside\Userstamps\Userstamps;

class Foo extends Model {

    use Userstamps;
}

use Wildside\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';
}

$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->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',
]);