PHP code example of yungts97 / laravel-user-activity-log
1. Go to this page and download the library: Download yungts97/laravel-user-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/ */
yungts97 / laravel-user-activity-log example snippets
use Illuminate\Database\Eloquent\Model;
use Yungts97\LaravelUserActivityLog\Traits\Loggable;
class Post extends Model
{
use Loggable; // add it in here
...
}
# BaseModel.php
use Illuminate\Database\Eloquent\Model;
use Yungts97\LaravelUserActivityLog\Traits\Loggable;
class BaseModel extends Model
{
use Loggable;
}
# PostModel.php
class Post extends BaseModel
{
...
}
use Yungts97\LaravelUserActivityLog\Traits\SkipLogging;
class Post extends BaseModel
{
use SkipLogging;
...
}
use Yungts97\LaravelUserActivityLog\Traits\SkipLogging;
class Post extends BaseModel
{
public $log_hidden = ['created_at', 'description'];
...
}
Log::all();
$post->logs; // get all model's logs
$post->log; // get the latest model's log
$post->logs()->where('log_type', 'edit')->get(); // get filtered logs
# config/user-activity-log.php
# only can choose either one of them
'mode' => 'full', # the 'full' mode record everything
'mode' => 'simple', # the 'simple' mode only record the modified columns
return [
# add your own middleware here (route middleware)
'middleware' => ['api', 'auth'],
# user model class
'user_model' => "App\Models\User",
# exclude tables for filter option
'exclude_tables' => [
'logs',
'migrations',
'failed_jobs',
'password_resets',
'personal_access_tokens',
],
# events to log
'events' => [
'create' => true,
'edit' => true,
'delete' => true,
'retrieve' => false,
'login' => true,
'logout' => true
],
# the mode is only for 'edit' event log
# the 'simple' mode only record the modified columns
# the 'full' mode record everything
# supported mode => 'simple' / 'full'
'mode' => 'full',
# timezone for log date time (Change to your region time zone, or any other variation of the timezone key in .env)
# UTC is the default the time zone being recorded.
# define your timezone to have the accurate logs time and filtered record (Especially filtered by date time)
'timezone' => env('APP_TIMEZONE','UTC')
];
bash
php artisan user-activity-log:install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.