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

Laravel Elfinder Laravel Package

barryvdh/laravel-elfinder

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require barryvdh/laravel-elfinder
    

    Publish the config and migrations:

    php artisan vendor:publish --provider="Barryvdh\Elfinder\ElfinderServiceProvider" --tag="config"
    php artisan vendor:publish --provider="Barryvdh\Elfinder\ElfinderServiceProvider" --tag="migrations"
    

    Run migrations:

    php artisan migrate
    
  2. Basic Configuration Edit config/elfinder.php to define storage disks (e.g., public, local):

    'disks' => [
        'public' => [
            'driver' => 'public',
            'root'   => '/',
        ],
    ],
    
  3. First Use Case: File Manager in a Blade View Add the ElFinder JS/CSS and initialize it in a Blade template:

    @elfinder('elfinder', [
        'disabled' => false,
        'lang' => 'en',
        'theme' => 'default',
        'resizable' => true,
        'uploadAllow' => ['image/*', 'application/pdf'],
    ])
    

    Include the JS/CSS in your layout:

    @vite(['resources/css/elfinder.min.css', 'resources/js/elfinder.min.js'])
    

Implementation Patterns

Common Workflows

  1. Restricting File Access Use middleware or disk configuration to limit access to specific folders:

    'disks' => [
        'restricted' => [
            'driver' => 'local',
            'root'   => storage_path('app/restricted'),
            'visibility' => 'private', // Only accessible via ElFinder
        ],
    ],
    
  2. Customizing File Uploads Extend the upload handler via events (e.g., elfinder.uploading):

    Elfinder::uploading(function ($file) {
        // Modify file metadata or validate before upload
        if ($file->mime === 'image/jpeg') {
            $file->name = 'custom_' . $file->name;
        }
    });
    
  3. Integration with Forms Use ElFinder’s input command to generate hidden fields for file paths:

    <input type="hidden" name="file_path" id="file_path">
    

    Initialize ElFinder with a callback to populate the field:

    $('#elfinder').elfinder({
        url: '/elfinder',
        commandsOptions: {
            getfile: {
                oncomplete: 'fileCallback'
            }
        }
    }).on('fileCallback', function(event, obj) {
        $('#file_path').val(obj.target.url);
    });
    
  4. Dynamic Disk Switching Pass the disk dynamically via JavaScript:

    $('#elfinder').elfinder({
        url: '/elfinder?disk=public',
    });
    

Advanced Patterns

  • Custom Commands: Extend ElFinder’s functionality by adding custom commands (e.g., bulk rename, thumbnail generation).
  • API Integration: Use ElFinder’s RESTful endpoints to build custom file management APIs.
  • Multi-Tenant Support: Scope ElFinder to user-specific storage using middleware or disk drivers.

Gotchas and Tips

Common Pitfalls

  1. Permission Issues

    • Ensure the storage directory has proper permissions (chmod -R 755 storage/).
    • For public disk, verify storage/app/public is symlinked to public/storage.
  2. CSRF Token Mismatch ElFinder requires CSRF protection. If using API routes, exclude them from verification:

    // app/Http/Middleware/VerifyCsrfToken.php
    protected $except = [
        'elfinder/*',
    ];
    
  3. CORS Errors (AJAX) If ElFinder is used in a SPA, configure CORS for the /elfinder endpoint:

    // app/Http/Middleware/Cors.php
    $allowedMethods = ['*'];
    $allowedOrigins = ['http://your-app.dev'];
    
  4. Disk Driver Quirks

    • Local Disk: Ensure root paths are absolute (e.g., storage_path('app')).
    • S3/FTP: Configure credentials in config/filesystems.php and reference them in elfinder.php:
      'disks' => [
          's3' => [
              'driver' => 's3',
              'bucket' => 'your-bucket',
          ],
      ],
      

Debugging Tips

  • Enable Logging: Set debug: true in config/elfinder.php to log requests/responses.
  • Check Network Tab: Inspect AJAX calls to /elfinder for errors (e.g., 403 Forbidden).
  • Clear Cache: After config changes, run:
    php artisan cache:clear
    php artisan config:clear
    

Extension Points

  1. Custom Templates Override ElFinder’s UI templates by publishing and modifying:

    php artisan vendor:publish --tag="elfinder-views"
    
  2. Event Hooks Listen for ElFinder events (e.g., elfinder.deleting, elfinder.uploaded) in EventServiceProvider:

    protected $listen = [
        'Barryvdh\Elfinder\Events\FileDeleted' => [
            'App\Listeners\LogDeletedFile',
        ],
    ];
    
  3. Middleware for Authorization Use Laravel middleware to restrict ElFinder access:

    Elfinder::middleware(['auth', 'can:manage-files']);
    
  4. Custom Drivers Extend Barryvdh\Elfinder\Driver\AbstractDriver to support new storage backends (e.g., Dropbox).

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