PHP code example of pekhota / nova-multifile

1. Go to this page and download the library: Download pekhota/nova-multifile 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/ */

    

pekhota / nova-multifile example snippets


use Pekhota\NovaMultiFile\MultiFile;

class ImportDocuments extends Action
{
    public $withoutActionEvents = true;

    public function fields(NovaRequest $request): array
    {
        return [
            MultiFile::make('Documents')
                ->accept(['.pdf', '.docx', '.xlsx'])
                ->maxFiles(10)
                ->help('Upload up to 10 documents.'),
        ];
    }

    public function handle(ActionFields $fields, Collection $models): mixed
    {
        /** @var \Illuminate\Http\UploadedFile[] $files */
        $files = $fields->get('documents'); // always an array, or null if nothing uploaded

        if (empty($files)) {
            return Action::danger('No files were uploaded.');
        }

        foreach ($files as $file) {
            $path = $file->store('documents', 'local');
            // … further processing
        }

        return Action::message(sprintf('Imported %d file(s).', count($files)));
    }
}

// In your action's handle():
$files = $fields->get('documents'); // UploadedFile[] or null