PHP code example of ge-tracker / basic-activity-log

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

    

ge-tracker / basic-activity-log example snippets


//at the top of your file you should import the facade.
use Activity;
...
/*
  The log-function takes two parameters:
  	- $text: the activity you wish to log.
  	- $user: optional can be an user id or a user object.
  	         if not proved the id of Auth::user() will be used

*/
Activity::log('Some activity that you wish to log');

use GeTracker\BasicActivityLog\Contracts\LogsActivity as LogsActivityContract;
use GeTracker\BasicActivityLog\LogsActivity;
use Illuminate\Database\Eloquent\Model;

class Article extends Model implements LogsActivityContract
{
   use LogsActivity;
...

/**
 * Get the message that needs to be logged for the given event name.
 *
 * @param string $eventName
 * @return string
 */
public function getActivityDescriptionForEvent($eventName)
{
    if ($eventName == 'created')
    {
        return 'Article "' . $this->name . '" was created';
    }

    if ($eventName == 'updated')
    {
        return 'Article "' . $this->name . '" was updated';
    }

    if ($eventName == 'deleted')
    {
        return 'Article "' . $this->name . '" was deleted';
    }

    return '';
}

'beforeHandler' => '\App\Handlers\BeforeHandler',



namespace App\Handlers;

use GeTracker\BasicActivityLog\Contracts\BeforeHandler;

class BeforeHandler implements BeforeHandler
{
    public function shouldLog($text, $userId)
	{
		if ($userId == 1) {return false;}

		return true;
	}
}

use GeTracker\BasicActivityLog\Models\Activity;

$latestActivities = Activity::with('user')->latest()->limit(100)->get();

Activity::cleanLog();
bash
php artisan vendor:publish --provider="GeTracker\BasicActivityLog\BasicActivityLogServiceProvider" --tag="migrations"
php artisan migrate
bash
php artisan vendor:publish --provider="GeTracker\BasicActivityLog\BasicActivityLogServiceProvider" --tag="config"
config/basic-basic-activitylog.php