PHP code example of victorscatolon / filament-attachment-library

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

    

victorscatolon / filament-attachment-library example snippets


use VictorScatolon\FilamentAttachmentLibrary\Core\InteractsWithAttachments;

class MyModel extends Model
{
    use InteractsWithAttachments;
}

use VictorScatolon\FilamentAttachmentLibrary\Forms\Components\AttachmentLibraryFileUpload;

public static function form(Form $form): Form
{
    return $form
        ->schema([
            AttachmentLibraryFileUpload::make(),
        ]);
}

use VictorScatolon\FilamentAttachmentLibrary\Core\HandleAttachments;

class CreateMyModel extends CreateRecord
{
    use HandleAttachments;
}

use VictorScatolon\FilamentAttachmentLibrary\Core\HandleAttachments;

class EditMyModel extends EditRecord
{
    use HandleAttachments;
}

use VictorScatolon\FilamentAttachmentLibrary\Core\HandleAttachments;

class MyRelationManager extends RelationManager
{
    use HandleAttachments;
}

public function form(Form $form): Form
{
    return $form
        ->schema([
            AttachmentFileUpload::make()->dehydrated(true),
        ]);
}

public function table(Table $table): Table
{
    return $table->headerActions([
            Tables\Actions\CreateAction::make()
                ->after(function ($record, $data) {
                    $attachments = $data['attachments'];
                    $this->handleAttachments($record, $attachments);
                }),
        ]);
}
bash
php artisan vendor:publish --tag="filament-attachment-library-migrations"
bash
php artisan make:model MyModel