PHP code example of tasmir / activity-tracker

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

    

tasmir / activity-tracker example snippets


use Tasmir\ActivityTracker\Services\UserActivityService;

public function update(Request $request, Profile $profile, UserActivityService $service)
{
    $profile->update($request->all());

    $service->store(
        $profile,         // The model instance
        Profile::class,   // Model class name
        'profile_update', // Action name
        'User updated their profile information' // Description
    );
}

'track_login' => true,
'track_logout' => true,

'track_url_visits' => true,

use Tasmir\ActivityTracker\Http\Middleware\TrackUrlVisit;

->withMiddleware(function (Middleware $middleware) {
    $middleware->append(TrackUrlVisit::class);
})

'detailed_url_tracking' => [
    'enabled' => true,
],

use Tasmir\ActivityTracker\Http\Middleware\TrackDetailedUrlVisit;

->withMiddleware(function (Middleware $middleware) {
    $middleware->append(TrackDetailedUrlVisit::class);
})

'log_cleanup' => [
    'enabled' => true,
    'retention_days' => 30,
    'schedule' => 'daily', // Options: daily, weekly, monthly
],

$user = User::find(1);
$logs = $user->activities; // Returns a collection of UserActivity models
bash
php artisan migrate
bash
php artisan vendor:publish --tag="activity-tracker-config"
bash
php artisan track:model User
bash
php artisan track:list
bash
php artisan track:all
bash
php artisan track:remove User
bash
php artisan make:model Product
# Automatically triggers: php artisan track:model Product
bash
php artisan migrate
bash
php artisan track:cleanup --days=15