This package is for create galleriable modules
kakhura/laravel-galleriable is a Laravel package for this package is for create galleriable modules.
It currently has 0 GitHub stars and 11 downloads on Packagist (latest version 1.0.1).
Install it with composer require kakhura/laravel-galleriable.
Discover more Laravel packages by kakhura
or browse all Laravel packages to compare alternatives.
Last updated
This package is for create modules, which has media gallery.
Add the package in your composer.json by executing the command.
composer require kakhura/laravel-galleriable
For Laravel versions before 5.5 or if not using auto-discovery, register the service provider in config/app.php
'providers' => [
/*
* Package Service Providers...
*/
\Kakhura\Galleriable\GalleriableServiceProvider::class,
],
If you want to change default configuration, you must publish default configuration file to your project by running this command in console:
php artisan vendor:publish --tag=kakhura-galleriable-config
This command will copy file [/vendor/kakhura/laravel-galleriable/config/kakhura.galleriable.php] to [/config/kakhura.galleriable.php]
Default kakhura.galleriable.php looks like:
return [
/**
* Use soft deletes into models and database.
*/
'use_soft_deletes' => true,
];
This command will copy file [/vendor/kakhura/laravel-galleriable/resources/views] to [/resources/views/vendor/admin/galleriable]
After publish Configuration, you must publish migrations, by running this command in console:
php artisan vendor:publish --tag=kakhura-galleriable-migrations
This command will copy file [/vendor/kakhura/laravel-galleriable/database/migrations] to [/database/migrations]
After publish Migrations, you must add HasGallery trait in your model which you want to has gallery:
use Kakhura\Galleriable\Traits\Models\HasGallery;
class Post extends Model
{
use HasGallery;
}
You must sync Gallery in all your model create functionality like this:
use Models\Post;
class PostService extends Service
{
public fucntion create(array $data)
{
...
$post = Post::create($data);
$images = [];
foreach (Arr::get($data, 'images') as $key => $image) {
$file = Helper::uploadFile($data, $fileType);
$images[] = [
'image_id' => $file->id,
'sort_index' => $key,
];
}
$post->syncGallery($images);
...
}
}
Enjoy.