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"),
        ])
    ...

return [
    // Specify your role model (must be compatible with spatie/laravel-permission)
    "role_model" => App\Models\Role::class,
    
    // Navigation configuration
    "navigation" => [
        "should_register_navigation" => true,
        "icon" => "heroicon-o-clipboard-document-check",
        "sort" => 1
    ],
    
    // Comment settings
    "enable_approval_comments" => false, // Allow comments when approving
    "enable_rejection_comments" => true, // Allow comments when rejecting
];

// In your published ApprovalFlowResource
class ApprovalFlowResource extends Resource
{
    // Add custom form fields
    public static function form(Form $form): Form
    {
        return $form->schema([
            // ... existing fields ...
            
            // Add your custom fields
            TextInput::make('custom_field')
                ->label('Custom Configuration'),
        ]);
    }
    
    // Customize table columns
    public static function table(Table $table): Table
    {
        return $table->columns([
            // ... existing columns ...
            
            // Add custom columns
            TextColumn::make('custom_data')
                ->label('Custom Information'),
        ]);
    }
}
bash
php artisan migrate
bash
php artisan approvals:publish
bash
php artisan approvals:publish --config
bash
php artisan approvals:publish --views
bash
php artisan approvals:publish --resources
bash
php artisan approvals:publish --components
bash
php artisan approvals:publish --translations
bash
php artisan approvals:publish --stubs