jargoud / laravel-backpack-dropzone

Dropzone field for Laravel Backpack
MIT License
2 stars 1 forks source link

Laravel Backpack Dropzone

Latest Version on Packagist Build Status Quality Score Total Downloads

This package provides a Dropzone field for Laravel Backpack.

Installation

You can install the package via composer:

composer config repositories.laravel-backpack-dropzone vcs https://github.com/jargoud/laravel-backpack-dropzone.git
composer require jargoud/laravel-backpack-dropzone

Then, publish the package assets and config:

php artisan vendor:publish --provider="Jargoud\LaravelBackpackDropzone\Providers\LaravelBackpackDropzoneServiceProvider"

As this package relies on pionl/laravel-chunk-upload, you can publish its config:

php artisan vendor:publish --provider="Pion\Laravel\ChunkUpload\Providers\ChunkUploadServiceProvider"

Usage

In your Backpack CRUD controller, add a dropzone field:

CRUD::addField([
    'name' => 'video',
    'type' => 'dropzone',
    'view_namespace' => 'dropzone::fields',
    'allow_multiple' => false, // false if missing key
    'config' => [
        // any option from the Javascript library
        'chunkSize' => 1024 * 1024 * 2, // for 2 MB
        'chunking' => true,
    ],
]);

Library options can be found on Dropzone documentation.

In your request, to validate the input value, use our Dropzone rule:

use Jargoud\LaravelBackpackDropzone\Rules\Dropzone;

public function rules(): array {
    return [
        'video' => [
            new Dropzone(['video/mp4']),
        ],
        'photos' => [
            'array',
        ],
        'photos.*' => [
            new Dropzone(['image/png'], [MyModel::find($this->id), "isPhotoFileExisting"]),
        ],
    ];
}

It works like Laravel's mimetypes validation rule and needs an array of mime types.

Then, uploaded file is stored in storage/app/upload. It can be handled through Laravel's filesystem:

\Storage::disk(config('chunk-upload.storage.disk'))->path($filePath);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Development

Assets

To compile assets, run the following commands:

npm install
npm run mix

It will generate CSS and JS files in resources directory.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email jeremy.argoud@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.