PHP code example of lastdino / approval-flow

1. Go to this page and download the library: Download lastdino/approval-flow 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/ */

    

lastdino / approval-flow example snippets


return [
    /**
     * This is the name of the table that contains the roles used to classify users
     * (for spatie-laravel-permissions it is the `roles` table
     */
    'roles_model' => "\\Spatie\\Permission\\Models\\Role",

    /**
     * The model associated with login and authentication
     */
    'users_model' => "\\App\\Models\\User",

    /*
    |--------------------------------------------------------------------------
    | Routes Configuration
    |--------------------------------------------------------------------------
    */
    'routes' => [
        'prefix' => 'flow',
        'middleware' => ['web'],
        'guards' => ['web'],
    ],

    /*
    |--------------------------------------------------------------------------
    | Date and Time Configuration
    |--------------------------------------------------------------------------
    */
    'datetime' => [
        'formats' => [
            'default' => 'Y-m-d H:i:s',
            'date' => 'Y-m-d',
            'time' => 'H:i:s',
            'year_month' => 'Y-m',
        ],
    ],

    /**
     * User Display Configuration
     */
    'user' => [
        'display_name_column' => 'Full_name',
        'fallback_columns' => ['full_name', 'display_name','name'],
    ],
];



namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Lastdino\ApprovalFlow\Traits\HasApprovalFlow;

class Document extends Model
{
    use HasApprovalFlow;

    // モデルの実装
}

// モデルインスタンス(承認対象)
$document = Document::find(1);

// 承認フロータスクを登録
$task = $document->registerApprovalFlowTask(
    flowId: 1,              // 使用する承認フローのID
    authorId: Auth::id(),   // 申請者のユーザーID
    comment: '承認お願いします', // 任意のコメント
    systemRoles: [1, 2] // 承認者のロールid(オプション)
);


// タスクをキャンセルする
$document->cancelApprovalFlowTask(
    userId: Auth::id(),      // キャンセルを実行するユーザーのID(通常は申請者自身)
    comment: 'キャンセルの理由' // キャンセル理由(オプション)
);

// モデルクラス内でメソッドをオーバーライド
class Document extends Model
{
    use HasApprovalFlow;

    /**
     * 承認時の振る舞いをカスタマイズ
     */
    public function onApproved(): void
    {
        // デフォルトの振る舞い
        $this->update(['status' => 'approved']);

        // 追加の処理例
        event(new DocumentApproved($this));
        Mail::to($this->author->email)->send(new DocumentApprovedMail($this));
    }

    /**
     * 拒否時の振る舞いをカスタマイズ
     */
    public function onRejected(): void
    {
        // デフォルトの振る舞い
        $this->update(['status' => 'rejected']);

        // 追加の処理例
        event(new DocumentRejected($this));
        Mail::to($this->author->email)->send(new DocumentRejectedMail($this));
    }
}

'users_model' => "\\App\\Models\\User",
'roles_model' => "\\Spatie\\Permission\\Models\\Role", // または独自のロールモデル

'user' => [
    'display_name_column' => 'Full_name',
    'fallback_columns' => ['full_name', 'display_name', 'name'],
],
bash
php artisan vendor:publish --tag="approvalflow-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="approvalflow-config"
bash
php artisan vendor:publish --tag="approvalflow-views"
bash
php artisan vendor:publish --tag="approvalflow-lang"
bash
php artisan vendor:publish --tag="approvalflow-assets"
blade
<!-- resources/views/layouts/app.blade.php または他のレイアウトファイル -->
@stack('approval-flow')
<body>
    <!-- 残りのレイアウト内容 -->
</body>
bash
php artisan vendor:publish --tag="approvalflow-assets"