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 Filemanager Laravel Package

unisharp/laravel-filemanager

UniSharp Laravel Filemanager adds a responsive web UI to browse, upload, manage, and select files/images in Laravel apps. Supports popular editors, configurable disks/paths, customization, and events—ideal for CMS/admin panels.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:
    composer require unisharp/laravel-filemanager
    php artisan vendor:publish --tag=lfm_config --tag=lfm_public
    php artisan storage:link
    
  2. Configure Routes (in routes/web.php):
    Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'auth']], function () {
        \UniSharp\LaravelFilemanager\Lfm::routes();
    });
    
  3. First Use Case:
    • Visit /laravel-filemanager/demo to test the UI.
    • Integrate with a WYSIWYG editor (e.g., CKEditor) by referencing the demo blade file (vendor/unisharp/laravel-filemanager/src/views/demo.blade.php).

Implementation Patterns

Core Workflows

  1. WYSIWYG Integration:

    • CKEditor: Use filebrowserImageBrowseUrl/filebrowserUploadUrl for image/file handling.
      CKEDITOR.replace('editor', {
        filebrowserImageBrowseUrl: '/laravel-filemanager?type=Images',
        filebrowserImageUploadUrl: '/laravel-filemanager/upload?type=Images&_token={{csrf_token()}}'
      });
      
    • TinyMCE: Override file_picker_callback to open the filemanager as a modal.
      file_picker_callback: (callback, value, meta) => {
        tinyMCE.activeEditor.windowManager.openUrl({
          url: `/laravel-filemanager?type=${meta.filetype === 'image' ? 'Images' : 'Files'}`,
          onMessage: (api, message) => callback(message.content)
        });
      }
      
  2. Standalone Upload Button:

    • Use the iframe or direct upload endpoint:
      <iframe src="/laravel-filemanager?type=Files" width="100%" height="500px"></iframe>
      
    • Or trigger via JavaScript:
      window.open('/laravel-filemanager?type=Images', '_blank', 'width=800,height=600');
      
  3. Multi-User Mode:

    • Configure lfm_disk and lfm_user_folder in config/lfm.php:
      'lfm_disk' => 'public',
      'lfm_user_folder' => 'users/{user_id}/',
      
    • Shared folders: Set lfm_shared_folder to a public directory (e.g., 'shared/').
  4. Cloud Storage:

    • Use Laravel’s filesystem (e.g., S3) by setting lfm_disk to your configured disk:
      'lfm_disk' => 's3',
      
    • Ensure the disk is properly configured in config/filesystems.php.

Integration Tips

  • Dynamic Routes: Customize routes via config/lfm.php:
    'routes' => [
        'prefix' => 'custom-filemanager',
        'upload' => 'upload',
        'show'  => 'show',
    ],
    
  • Middleware: Restrict access by adding middleware to the route group:
    Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'auth', 'verified']], function () {
        \UniSharp\LaravelFilemanager\Lfm::routes();
    });
    
  • Localization: Set the default locale in config/lfm.php:
    'locale' => 'es', // e.g., 'es' for Spanish
    
  • Custom Views: Override default views by publishing them and modifying:
    php artisan vendor:publish --tag=lfm_view
    
    Then edit resources/views/vendor/lfm/....

Gotchas and Tips

Pitfalls

  1. Namespace Issues:

    • After upgrading, clear caches and reinstall if encountering Class not found errors:
      composer remove unisharp/laravel-filemanager && composer require unisharp/laravel-filemanager
      php artisan config:clear
      
    • Ensure UniSharp (not Unisharp) is used in autoloaded code.
  2. Permission Errors:

    • Verify storage/ and public/ directories are writable:
      chmod -R 775 storage/ public/
      
    • For cloud storage (e.g., S3), ensure IAM roles have proper permissions.
  3. CSRF Token:

    • Always include _token={{csrf_token()}} in upload URLs for security:
      filebrowserImageUploadUrl: '/laravel-filemanager/upload?type=Images&_token={{csrf_token()}}'
      
  4. Image Processing:

    • Requires gd or imagick PHP extensions. Test with:
      php -m | grep -E 'gd|imagick'
      
    • For intervention/image v4+, ensure PHP 8.3+ is used.
  5. Route Conflicts:

    • Clear routes after publishing:
      php artisan route:clear
      
    • Avoid naming conflicts with existing routes (e.g., laravel-filemanager prefix).

Debugging Tips

  1. Logs:

    • Check storage/logs/laravel.log for upload errors or permission issues.
    • Enable debug mode in config/lfm.php:
      'debug' => env('APP_DEBUG', false),
      
  2. Network Tab:

    • Inspect failed uploads in browser dev tools (check for 413/419 errors).
    • Validate Content-Type headers (e.g., multipart/form-data).
  3. Storage Paths:

    • Verify lfm_filesystem_disk and lfm_filesystem_folder in config/lfm.php point to valid paths:
      'lfm_filesystem_disk' => 'public',
      'lfm_filesystem_folder' => 'uploads',
      
  4. Events:

    • Listen for file operations via events (e.g., lfm.uploaded):
      \UniSharp\LaravelFilemanager\Events\AfterUpload::class => [YourHandler::class, 'handleUpload'],
      

Extension Points

  1. Custom Validation:

    • Extend upload validation by overriding the validateUpload method in a service provider:
      \UniSharp\LaravelFilemanager\Services\LfmService::macro('validateUpload', function ($request) {
          $request->validate([
              'file' => ['required', 'mimes:jpg,png,pdf', 'max:10240'], // Custom rules
          ]);
      });
      
  2. File Processing:

    • Hook into lfm.afterUpload event to process files post-upload:
      \UniSharp\LaravelFilemanager\Events\AfterUpload::class => function ($event) {
          // Example: Generate a thumbnail
          \Image::make($event->file->getRealPath())->resize(100, 100)->save(public_path('thumbs/' . $event->file->getClientOriginalName()));
      };
      
  3. UI Customization:

    • Override Blade templates (e.g., lfm::partials.upload) in resources/views/vendor/lfm/.
    • Extend JavaScript by including custom scripts in the filemanager’s footer:
      // In config/lfm.php
      'javascript' => [
          'custom.js' => '/path/to/custom.js',
      ],
      
  4. API Integration:

    • Use the underlying LfmService for programmatic file operations:
      use UniSharp\LaravelFilemanager\Services\LfmService;
      
      $lfm = app(LfmService::class);
      $files = $lfm->getFiles('Images', '/path/to/folder');
      
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony