PHP code example of nvl / activity

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

    

nvl / activity example snippets


'events' => [
    'order.approved' => [
        'subject_types' => ['order'], // Use your actual morph alias.
        'actor' => ',
        'redacted_fields' => ['private_note'],
        'retention_days' => 365,
        'audience' => 'authorized',
    ],
],

use Nvl\Activity\Services\ActivityRecorder;
use Nvl\Activity\Services\ActivityReader;

$fact = app(ActivityRecorder::class)->record([
    'subject' => $order,
    'event' => 'order.approved',
    'log_name' => 'orders',
    'context' => ['reason' => 'Reviewed'],
    'attributes' => ['status' => 'approved'],
    'old' => ['status' => 'pending'],
], $actor);

$page = app(ActivityReader::class)->paginate([
    'events' => ['order.approved'],
    'per_page' => 20,
    'page' => 1,
], $actor);
$timeline = app(ActivityReader::class)->timeline($order, $actor, 50);
$causers = app(ActivityReader::class)->causers($actor, search: 'Ada', limit: 10);

use Nvl\Activity\Services\ActivityCaptureContext;

app(ActivityCaptureContext::class)->run($actor, function () use ($order): void {
    $order->getConnection()->transaction(function () use ($order): void {
        $order->update(['status' => 'approved']);
    });
});