prodixx/dropzone-field-for-backpack

Dropzone field for Laravel Backpack

2.2.0 2023-06-06 11:32 UTC

This package is auto-updated.

Last update: 2024-05-06 13:56:13 UTC


README

Latest Version on Packagist Total Downloads The Whole Fruit Manifesto

This package provides a Dropzone field type for projects that use the Backpack for Laravel administration panel.

More exactly, the dropzone field type allows admins to upload multiple images to a crud entity. After uploading you can reorder the images simply by drag and drop.

Screenshots

Backpack Toggle Field Addon

Installation

Via Composer

composer require prodixx/dropzone-field-for-backpack

Usage

For the moment you can use drozone field only on update operantions. So, to use it, inside your custom CrudController do:

namespace App\Http\Controllers\Admin;

use Prodixx\DropzoneFieldForBackpack\Traits\DropzoneTrait;

class ProductCrudController extends CrudController
{
    use DropzoneTrait;

    protected function setupUpdateOperation()
    {
        $this->setupCreateOperation();

        CRUD::addField(
            [
                'name'             => 'images',
                'label'            => 'Images',
                'type'             => 'dropzone',
                'disk'             => 'public',
                'destination_path' => 'products/',
                'image_width'      => 800,
                'image_height'     => 600,
                'mimes'            => 'image/*',
                'max_file_size'    => 5, // MB
                'webp'             => true, // (optional) also save webp version
                'view_namespace'   => 'prodixx.dropzone-field-for-backpack::fields',
                'thumb_prefix'     => '',
                // 'hint'          => 'Some info', // (optional) some text that is shown under the field
                // 'tab'           => 'Images', // (optional) if you want the field to be shown in tabs
            ],
        );
    }
}

Notice the view_namespace attribute - make sure that is exactly as above, to tell Backpack to load the field from this addon package, instead of assuming it's inside the Backpack\CRUD package.

Overwriting

If you need to change the field in any way, you can easily publish the file to your app, and modify that file any way you want. But please keep in mind that you will not be getting any updates.

Step 1. Copy-paste the blade file to your directory:

# create the fields directory if it's not already there
mkdir -p resources/views/vendor/backpack/crud/fields

# copy the blade file inside the folder we created above
cp -i vendor/prodixx/dropzone-field-for-backpack/src/resources/views/fields/dropzone.blade.php resources/views/vendor/backpack/crud/fields/dropzone.blade.php

Step 2. Remove the vendor namespace wherever you've used the field:

    CRUD::addField(
        [
            'name'             => 'images',
            'label'            => 'Images',
            'type'             => 'dropzone',
            'disk'             => 'public',
            'destination_path' => 'products/',
            'image_width'      => 800,
            'image_height'     => 600,
            'mimes'            => 'image/*',
            'max_file_size'    => 5, // MB
            'webp'             => true,
-           'view_namespace' => 'prodixx.dropzone-field-for-backpack::fields'
            'thumb_prefix'     => '',
            // 'hint'          => 'Some info', // (optional) some text that is shown under the field
            // 'tab'           => 'Images', // (optional) if you want the field to be shown in tabs
        ],
    );

Step 3. Uninstall this package. Since it only provides one file, and you're no longer using that file, it makes no sense to have the package installed:

composer remove prodixx/dropzone-field-for-backpack

Change log

Changes are documented here on Github. Please see the Releases tab.

Contributing

Please see contributing.md for a todolist and howtos.

Security

If you discover any security related issues, please email catalin.prodan@newpixel.ro instead of using the issue tracker.

Credits

License

This project was released under MIT, so you can install it on top of any Backpack & Laravel project. Please see the license file for more information.

However, please note that you do need Backpack installed, so you need to also abide by its YUMMY License. That means in production you'll need a Backpack license code. You can get a free one for non-commercial use (or a paid one for commercial use) on backpackforlaravel.com.