alexd/image

Image Manager for using in forms

Installs: 32

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Language:JavaScript

dev-master 2017-08-03 13:40 UTC

This package is not auto-updated.

Last update: 2024-11-06 00:16:08 UTC


README

Installation

  1. Require the package via Composer in your composer.json
{
    "require": {
        "alexd/image": "*"
    }
}
  1. Run Composer update
$ composer update
  1. Add the service providers to your app/config/app.php file
Bkwld\Croppa\ServiceProvider::class,
Alexd\Image\ImageServiceProvider::class,
  1. Add the aliases to app/config/app.php file
'Croppa' => Bkwld\Croppa\Facade::class,
'ImageManager' => Alexd\Image\Facades\Image::class
  1. Run artisan commands
php artisan vendor:publish --provider="Alexd\Image\ImageServiceProvider"
php artisan storage:link
  1. if you already had config/croppa.php change setting values on following:
'src_dir' => public_path('storage'),
'crops_dir' => public_path('storage'),
'path' => 'storage/(.*)$',
'signing_key' => false,
'upscale' => true,

Usage

  1. On the create form add:

For single image:

@include('ImageManager::_scripts')
@include('ImageManager::_image-input', [
    'label' => 'Image',
    'field_name' => 'image',
    'upload_dir' => 'gallery',
    'size' => [100, 100]
])

For multiple images:

@include('ImageManager::_scripts')
@include('ImageManager::_images-input', [
    'label' => 'Images',
    'field_name' => 'images',
    'upload_dir' => 'gallery',
    'size' => [100, 100]
])
  1. On the edit form add:

For single image:

@include('ImageManager::_scripts')
@include('ImageManager::_image-input', [
    'label' => 'Image',
    'field_name' => 'image',
    'upload_dir' => 'gallery',
    'size' => [100, 100],
    'model' => $model
])

For multiple images:

@include('ImageManager::_scripts')
@include('ImageManager::_images-input', [
            'label' => 'Images',
            'field_name' => 'images',
            'upload_dir' => 'gallery',
            'size' => [100, 100],
            'model' => $model
        ])

Don't forget to add multipart/form-data to your forms

  1. On the store method you can use:

For single image:

$data = $request->all();

$data['image'] = ImageManager::upload($request, 'image', 'gallery');

For multiple images:

$data = $request->all();

ImageManager::multiupload($request, 'images', 'gallery', $model->id, Gallery::class);
  1. On the update method you can use:

For single image:

$data = $request->all();

$data['image'] = ImageManager::upload($request, 'image', 'gallery', $model->image);

For multiple images:

$data = $request->all();

ImageManager::multiupload($request, 'images', 'gallery', $model->id, Gallery::class);
  1. To delete image you should pass filename and upload dir

For single image:

ImageManager::delete($model->image, 'gallery');

For multiple images:

ImageManager::multidelete($model->images, 'gallery');