1. Go to this page and download the library: Download roketin/laravel-auditing 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/ */
// app/Team.php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Roketin\Auditing\AuditingTrait;
class Team extends Model
{
use AuditingTrait;
//...
}
// app/Team.php
namespace App;
use Roketin\Auditing\Auditing;
class Team extends Auditing
{
//...
}
// app/Team.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Team extends Model
{
use Roketin\Auditing\AuditingTrait;
// Disables the log record in this model.
protected $auditEnabled = false;
// Disables the log record after 500 records.
protected $historyLimit = 500;
// Fields you do NOT want to register.
protected $dontKeepLogOf = ['created_at', 'updated_at'];
// Tell what actions you want to audit.
protected $auditableTypes = ['created', 'saved', 'deleted'];
}
// app/Http/Controller/MyAppController.php
namespace App\Http\Controllers;
use App\Team;
class MyAppController extends BaseController
{
public function index()
{
$team = Team::find(1); // Get team
$team->logs; // Get all logs
$team->logs->first(); // Get first log
$team->logs->last(); // Get last log
$team->logs->find(2); // Selects log
}
//...
}
use Roketin\Auditing\Log;
$logs = Log::with(['user'])->get();
use App\Team;
$logs = Team::logs->with(['user'])->get();
> ...
> 'model' => App\User::class,
> ...
>
// app/Team.php
namespace App;
use Roketin\Auditing\Auditing;
class Team extends Auditing
{
//...
public static $logCustomMessage = '{user.name|Anonymous} {type} a team {elapsed_time}'; // with default value
public static $logCustomFields = [
'name' => 'The name was defined as {new.name||getNewName}', // with callback method
'owner' => [
'updated' => '{new.owner} owns the team',
'created' => '{new.owner|No one} was defined as owner'
],
];
public function getNewName($log)
{
return $log->new['name'];
}
//...
}
// app/Http/Controllers/MyAppController.php
//...
public function auditing()
{
$logs = Team::find(1)->logs; // Get logs of team
return view('auditing', compact('logs'));
}
//...