PHP code example of kuncen / audittrails

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

    

kuncen / audittrails example snippets



 'providers' => ServiceProvider::defaultProviders()->merge([
        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
         ...
         ...
         Kuncen\Audittrails\AudittrailsServiceProvider::class,
 ])->toArray(),



use Laravel\Sanctum\HasApiTokens;
use Kuncen\Audittrails\LogTransaction;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, LogTransaction;
}


    protected $setForeignValues = [
        [
            "foreign"         => "role_id", //foreign key in your models
            "reference_table" => "role", //reference table of your foreign key
            "reference_table_primary" => "role_id", //primary key of your reference table (not  "target_value"    => "some_target_column"
        ]
    ];

    $data = User::hideForeignId(false)->find(1);
    $data->name = "Dummy Example";
    $data->email = "[email protected]";
    $data->password = bcrypt("examplepassword");
    $data->update();

$data = User::withAuth(17)->find(1);
$data->name = "Dummy Example";
$data->email = "[email protected]";
$data->password = bcrypt("examplepassword");
$data->update();

$data = User::disableAudit(true)->find(1);
$data->name = "Dummy Example";
$data->email = "[email protected]";
$data->password = bcrypt("examplepassword");
$data->update();

setActivityLog(
    "description about this function/page/menu (opsional default is null)",
    user id (opsional if you need user identity for your function default is null),
    http method or action (opsional by default value is "READ"),
    "New values what you need to store it (opsional)",
    "Old values what you need to store it (opsional)"
);

php artisan vendor:publish --provider="Kuncen\Audittrails\AudittrailsServiceProvider"

php artisan migrate