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-based file manager to Laravel apps. Browse, upload, organize and delete files and images, integrate with editors like TinyMCE/CKEditor, configure disks, permissions, and customization options.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:
    composer require unisharp/laravel-filemanager
    php artisan vendor:publish --tag=lfm_config
    php artisan vendor:publish --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:
    • Access /laravel-filemanager/demo to test the UI.
    • Integrate with a WYSIWYG editor (e.g., CKEditor) via the provided plugin:
      <script src="//cdn.ckeditor.com/4.16.0/standard/ckeditor.js"></script>
      <script>
          CKEDITOR.editorConfig = function(config) {
              config.filebrowserBrowseUrl = '/laravel-filemanager?type=Files';
              config.filebrowserImageBrowseUrl = '/laravel-filemanager?type=Images';
              config.filebrowserUploadUrl = '/laravel-filemanager/upload';
              config.filebrowserUploadMethod = 'form';
          };
      </script>
      

Implementation Patterns

Core Workflows

  1. File Uploads:

    • Use the standalone upload button or WYSIWYG integration.
    • Validate uploads via valid_mime and max_size in config/lfm.php.
    • Example for TinyMCE:
      tinymce.init({
          selector: 'textarea',
          plugins: 'image',
          file_picker_callback: function(callback, value, meta) {
              var input = document.createElement('input');
              input.setAttribute('type', 'file');
              input.setAttribute('accept', 'image/*');
              input.onchange = function() {
                  var file = input.files[0];
                  var reader = new FileReader();
                  reader.onload = function() {
                      var id = 'blobid-' + (new Date()).getTime();
                      var blobCache = tinymce.activeEditor.editorUpload.blobCache;
                      var blobInfo = blobCache.create(id, file, reader.result);
                      callback(blobInfo.blobUri(), { title: file.name });
                  };
                  reader.readAsDataURL(file);
              };
              input.click();
          }
      });
      
  2. Image Processing:

    • Leverage Intervention/Image for cropping/resizing via events (e.g., ImageWasUploaded).
    • Example event listener:
      public function onImageWasUploaded(ImageWasUploaded $event) {
          $path = $event->path();
          $img = Image::make($path)->resize(300, 200)->save();
      }
      
  3. Multi-User Folders:

    • Private folders (user-specific) and shared folders (all users) are auto-managed.
    • Customize folder paths via private_folder_name and shared_folder_name in config.
  4. Cloud Storage:

    • Configure filesystems in config/filesystems.php (e.g., S3, FTP).
    • Set lfm_disk in config/lfm.php to use a custom disk.

Integration Tips

  • Standalone Upload: Use the iframe or JS API for custom upload buttons.
    <iframe src="/laravel-filemanager?type=Files" width="100%" height="500px"></iframe>
    
  • Dynamic Routes: Override routes by setting use_package_routes: false and defining custom routes.
  • Localization: Switch languages via ?locale=ar (supports 30+ locales).

Gotchas and Tips

Pitfalls

  1. Permissions:

    • Ensure storage/app/public and subdirectories are writable (chmod -R 775 storage/).
    • Symlink issues? Run php artisan storage:link --force.
  2. Image Processing:

    • Missing exif, fileinfo, or GD/Imagick extensions will break image features.
    • Debug with php -m to check extensions.
  3. Multi-User Mode:

    • Private folders require auth middleware; otherwise, users may access others' files.
    • Custom ConfigHandler requires publishing the handler:
      php artisan vendor:publish --tag=lfm_handler
      
  4. Caching:

    • Clear caches after config changes:
      php artisan route:clear
      php artisan config:clear
      

Debugging

  • Logs: Check storage/logs/laravel.log for upload errors.
  • Events: Use dd($event->path()) in listeners to inspect file paths.
  • UI Issues: Clear browser cache or check lfm_public assets for missing files.

Extension Points

  1. Custom Validation: Override validateUpload in a published Handler:

    public function validateUpload($request, $type) {
        $rules = parent::validateUpload($request, $type);
        $rules['file'][] = 'dimensions:max_width=2000,max_height=2000';
        return $rules;
    }
    
  2. Custom Views: Publish views and override templates (e.g., resources/views/vendor/lfm/).

  3. API Extensions: Extend the API via middleware or service providers:

    Lfm::addMiddleware('lfm', function ($request, $next) {
        if ($request->user()->isAdmin()) {
            return $next($request);
        }
        abort(403);
    });
    
  4. Cloud Storage Quirks:

    • S3: Ensure public ACL is set for uploaded files.
    • FTP: Use passive mode (ftp_passive_mode: true in config/filesystems.php).

Pro Tips

  • Batch Processing: Use events to auto-generate thumbnails or watermarks.
  • Soft Deletes: Extend the File model to support soft deletes via deleted_at.
  • Audit Logs: Log events to a database table for compliance:
    public function onFileWasUploaded(FileWasUploaded $event) {
        \App\Models\AuditLog::create([
            'user_id' => auth()->id(),
            'action' => 'file_uploaded',
            'path' => $event->path(),
        ]);
    }
    
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope