PHP code example of rajtika / mongovity

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

    

rajtika / mongovity example snippets


use Jenssegers\Mongodb\Eloquent\Model;

use MongoDB\Laravel\Eloquent\Model;

// Add ActivityTrait to the model you want to log
use Rajtika\Mongovity\Contracts\ActivityTrait;

// Log only specific attributes
protected static $logAttributes = ['name', 'email', 'status'];

// Or log fillable / all non-guarded attributes (for $guarded-only models)
protected static $logFillable = true;

// Skip logging when nothing changed on update
protected static $logOnlyDirty = true;

// Custom log message per event
public function getDescriptionForEvent(string $eventName): string
{
    return "MyModel {$eventName}";
}

// You can define specific events to be logged
protected $recordEvents = [
    'created',
    'updated',
    'deleted',
    'restored'
];
/** -----------OR--------- **/
protected $loggableEvents = [
    'created',
    'updated',
    'deleted',
    'restored'
];

// If you want to save a custom activity log
use Rajtika\Mongovity\Services\Mongovity;

app(Mongovity::class)
    ->by(Auth::user()) // Required *
    ->on(TestModel::find(1)) // optional
    ->event('created') // optional
    ->log('Your custom message');

/** OR **/
use Rajtika\Mongovity\Facades\Mongovity;

Mongovity::by(User::first())->log('Custom message');

public function getNameAttribute()
{
    return $this->first_name . ' ' . $this->last_name;
}

public function getMobileAttribute()
{
    return $this->mobile_number;
}

'layout' => 'layouts.app',
'content_section' => 'content',
'styles_stack' => 'styles',
'scripts_stack' => 'scripts',
bash
php artisan vendor:publish --tag=mongovity-views