Nova File Manager

website·Indexed 30 days ago

https://oneduo.github.io/nova-file-manager/

A performant file management package for Laravel Nova. It includes a FileManager field and tool, featuring access control, upload validation, and integrations with Cropper.js and the Pintura image editor. Supports PHP 8.0 or higher and provides event dispatching for FileUploading and FileUploaded actions.

Tokens
5.7K
Snippets
27
Records
40
Agent score
75%

What's inside Nova File Manager

  1. Overview of Nova File Manager for Laravel Nova

    Nova File Manager is a plug-and-play file management tool and field for Laravel Nova. It provides a customizable interface for managing assets across multiple disks and filesystems. Key capabilities include support for chunked uploads, local search, and the ability to save multiple assets within a single field. It is built using Tailwind CSS 3, Vue 3, and Vuex.
  2. Overview of Nova File Manager for Laravel Nova

    Nova File Manager is a plug-and-play file management tool and field for Laravel Nova. It provides a customizable interface for managing assets across multiple disks and filesystems.

    Key technical specifications and features include:

    • Compatibility: Laravel Nova 4 and PHP 8.
    • Tech Stack: Built with Tailwind CSS 3, Vue 3, and Vuex.
    • Capabilities: Supports chunked uploads, local search, and the ability to save multiple assets within a single field.
    • Storage: Supports multi-disk and filesystem configurations.
  3. Nova File Manager UI Overview

    The Nova File Manager interface includes the following functional areas:

    • Disk switcher dropdown
    • Pagination control dropdown
    • View mode toggle
    • Global search bar
    • New folder creation button
    • File upload button
    • Breadcrumbs for directory navigation
    • Folders and Files lists
    • Pagination controls
  4. Integrate Pintura image editor into Nova File Manager

    To integrate the Pintura image editor, first enable it in your .env file. Because Pintura is a paid library, you must provide your own licensed JS and CSS assets. These assets must be loaded into your application before the File Manager tool scripts. The integration requires defining a window.novaFileManagerEditor object containing the appendDefaultEditor function and an editorOptions configuration object.
    NOVA_FILE_MANAGER_USE_PINTURA=true
    <!-- In layout.blade.php -->
    <head>
        <!-- ... -->
        <link rel="stylesheet" href="{{ asset('pintura.css') }}">
    </head>
    <body>
        <!-- ... -->
        <script type="module">
          import { appendDefaultEditor } from '/pintura.js'
    
          const editorOptions = {}
    
          window.novaFileManagerEditor = {
            appendDefaultEditor,
            editorOptions,
          }
        </script>
    
        @if ($scripts = \Laravel\Nova\Nova::availableScripts(request()))
            @foreach ($scripts as $asset)
                <script src="{!! $asset->url() !!}"></script>
            @endforeach
        @endif
    </body>
  5. Manage Nova File Manager update notifications

    The Nova File Manager package includes a built-in automatic update checker that displays a subtle banner when a new update is available.

    Key behaviors:

    • Default State: Enabled by default.
    • Check Frequency: Checks for the latest release using a 1-hour cache.
    • Dismissal: The banner will automatically dismiss after 1 day, or can be manually dismissed by updating the package and clearing the application cache.

    To manually dismiss the update banner after updating the package, run the following command:

    php artisan cache:clear
  6. Integrate FileManager with third-party Nova tools

    To use the FileManager field inside custom fields or third-party tools (like Nova Settings or Flexible Content), you must register a wrapper in your NovaServiceProvider. This ensures the field is correctly resolved during API calls.

    1. Use the wrapper('wrapper_name') method on the field.
    2. Register the wrapper using FileManager::registerWrapper in the provider's register or boot method to apply configuration (like filesystems or permissions).
    3. Ensure the attribute is cast correctly (e.g., using AssetCollection::class).
    // In NovaServiceProvider.php
    
    public function boot()
    {
        NovaSettings::addSettingsFields(function () {
            return [
                FileManager::make('An image', 'image')
                    ->wrapper('my_wrapper'),
            ];
        }, [
            'image' => AssetCollection::class,
        ]);
    }
    
    public function register()
    {
        FileManager::registerWrapper('my_wrapper', function (FileManager $field) {
            return $field
                ->multiple()
                ->filesystem(fn() => 'public');
        });
    }
  7. Handle Nova File Manager events

    The Nova File Manager dispatches events to an event bus when specific file or folder actions are performed. You can subscribe to these events by adding a listener to the event bus. For 'before' hooks (events ending in -ing), you can prevent the action from proceeding by throwing a ValidationException.
  8. Run Nova File Manager from a local fork

    To contribute to the package and run it on a local Laravel Nova installation, fork the repository and add your fork's URL to the repositories section of your project's composer.json file.
    {
      "repositories": [
        {
          "type": "git",
          "url": "<your-fork-repository-git-url>"
        }
      ]
    }