PHP code example of eightynine / filament-approvals

1. Go to this page and download the library: Download eightynine/filament-approvals 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/ */

    

eightynine / filament-approvals example snippets



    ->plugins([
        \EightyNine\Approvals\ApprovalPlugin::make()
    ])


namespace App\Models;

use EightyNine\Approvals\Models\ApprovableModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class LeaveRequest extends ApprovableModel
{
    use HasFactory;

    protected $fillable = ["name"];
}


$table
    ->actions(
        ...\EightyNine\Approvals\Tables\Actions\ApprovalActions::make(
            // define your action here that will appear once approval is completed
            Action::make("Done"),
            [
                Tables\Actions\EditAction::make(),
                Tables\Actions\ViewAction::make()
            ]
        ),
    )



namespace App\Filament\Resources\LeaveRequestResource\Pages;

use App\Filament\Resources\LeaveRequestResource;
use Filament\Actions;
use Filament\Actions\Action;
use Filament\Resources\Pages\ViewRecord;

class ViewLeaveRequest extends ViewRecord
{
    use  \EightyNine\Approvals\Traits\HasApprovalHeaderActions;

    protected static string $resource = LeaveRequestResource::class;


    /**
     * Get the completion action.
     *
     * @return Filament\Actions\Action
     * @throws Exception
     */
    protected function getOnCompletionAction(): Action
    {
        return Action::make("Done")
            ->color("success")
            // Do not use the visible method, since it is being used internally to show this action if the approval flow has been completed.
            // Using the hidden method add your condition to prevent the action from being performed more than once
            ->hidden(fn(ApprovableModel $record)=> $record->shouldBeHidden())
    }
}


    return $table
        ->columns([
            TextColumn::make("name"),
            \EightyNine\Approvals\Tables\Columns\ApprovalStatusColumn::make("approvalStatus.status"),
        ])
    ...
bash
php artisan migrate