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
Requires
- php: >=5.4.0
- bkwld/croppa: ~4.0
- intervention/image: ^2.3
This package is not auto-updated.
Last update: 2024-11-06 00:16:08 UTC
README
Installation
- Require the package via Composer in your
composer.json
{
"require": {
"alexd/image": "*"
}
}
- Run Composer update
$ composer update
- Add the service providers to your
app/config/app.php
file
Bkwld\Croppa\ServiceProvider::class,
Alexd\Image\ImageServiceProvider::class,
- Add the aliases to
app/config/app.php
file
'Croppa' => Bkwld\Croppa\Facade::class,
'ImageManager' => Alexd\Image\Facades\Image::class
- Run artisan commands
php artisan vendor:publish --provider="Alexd\Image\ImageServiceProvider"
php artisan storage:link
- 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
- 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]
])
- 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
- 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);
- 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);
- 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');