Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

File Bundle Laravel Package

da-vinci-studio/file-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require da-vinci-studio/file-bundle
    

    (Note: This package is outdated and designed for Symfony, not Laravel. Adaptation required.)

  2. Directory Setup Create a directory (e.g., storage/app/document) for file storage.

  3. Configuration Manually define a service in config/services.php (Laravel equivalent of Symfony’s AppKernel):

    'dvs.file_receiver' => \Dvs\FileBundle\Service\FileReceiver::class,
    
  4. First Use Case Inject FileReceiver into a controller/service and upload a file:

    use Dvs\FileBundle\Service\FileReceiver;
    
    public function upload(Request $request, FileReceiver $receiver) {
        $file = $request->file('document');
        $receiver->save($file, 'document'); // 'document' = filesystem key
    }
    

Implementation Patterns

Core Workflow

  1. File Handling Use FileReceiver to abstract file storage logic:

    $receiver->save($file, 'document', [
        'original_name' => true, // Preserve original filename
        'overwrite' => false,    // Avoid overwrites
    ]);
    
  2. Filesystem Integration Extend with Laravel’s Filesystem facade for consistency:

    $receiver->setFilesystem(Storage::disk('local'));
    
  3. Validation Validate files before saving (Laravel’s ValidatedRequest):

    public function store(ValidatedRequest $request) {
        $request->validate(['file' => 'required|mimes:pdf,docx']);
    }
    

Advanced Patterns

  • Custom Storage Paths Override paths dynamically:

    $receiver->setBasePath('custom/path');
    
  • Event Listeners Trigger events post-upload (Laravel’s Events):

    event(new FileUploaded($filePath));
    

Gotchas and Tips

Pitfalls

  1. Symfony Dependency

    • The package expects Symfony’s OneupFlysystemBundle. Use Laravel’s League\Flysystem or spatie/laravel-medialibrary as alternatives.
  2. Outdated Code

    • Methods like save() may not align with Laravel’s UploadedFile interface. Wrap files:
    $receiver->save($request->file('file')->getRealPath(), 'document');
    
  3. Configuration Rigidity

    • parameters.yml is Symfony-specific. Use Laravel’s .env or config/filesystems.php.

Debugging Tips

  • Log File Paths Add debug logs for generated paths:

    \Log::debug('File saved to:', $receiver->getPath());
    
  • Filesystem Adapter Ensure the adapter matches Laravel’s FilesystemManager:

    $receiver->setAdapter(Storage::disk('local')->getAdapter());
    

Extension Points

  1. Custom Naming Strategy Override FileReceiver to implement unique naming (e.g., UUIDs):

    class CustomFileReceiver extends FileReceiver {
        protected function generateFilename() {
            return Str::uuid() . '.' . $this->getExtension();
        }
    }
    
  2. Post-Processing Chain with Laravel’s AfterUploading events or queues:

    FileUploaded::dispatch($file)->after(function ($event) {
        // Process file (e.g., generate thumbnail)
    });
    
  3. Testing Mock FileReceiver in tests:

    $receiver = Mockery::mock(FileReceiver::class);
    $receiver->shouldReceive('save')->once();
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui