PHP code example of itas / laravel-audit

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

    

itas / laravel-audit example snippets


    'providers' => [
        // ...
        itas\LaravelAudit\AuditServiceProvider::class,
    ]



namespace App\Model;

use Itas\LaravelAudit\Traits\HasAudit;
use Illuminate\Database\Eloquent\Model;

class Leave extends Model
{
    use HasAudit;

    protected $table = 'leave';
}




namespace App\Http\Controllers;

use Itas\LaravelAudit\Events\CreateRecorded;
use App\Model\Leave;

class LeaveController extends Controller
{
    // 创建请假单时,生成请假审核流
    public function create(Leave $leave)
    {
        $leave = $leave->create([]);

        $object = collect();
        $object->model = $leave;
        $object->users = [
            [
                'user_id' => 1,
                'node' => '组长',
                'sort' => 1
            ],
            [
                'user_id' => 2,
                'node' => '副总监',
                'sort' => 2
            ],
            [
                'user_id' => 3,
                'node' => '技术总监',
                'sort' => 3
            ],
            [
                'user_id' => 4,
                'node' => '人事',
                'sort' => 4
            ],
        ];
        event(new CreateRecorded($object));
    }
    
    // 显示审核流程图
    public function index(Leave $leave)
    {
        $audit = $leave->with('audit', 
                            'audit.currentAuditUser', 
                            'audit.auditUsers', 
                            'audit.auditRecords', 
                            'audit.auditUsers.auditer')
                        ->find(1)
                        ->toArray();
        
        return view('audit.stream', compact('audit'));
    }
}

$ php artisan vendor:publish
$ php artisan migrate