Package Data | |
---|---|
Maintainer Username: | neonbug |
Package Create Date: | 2015-11-12 |
Package Last Update: | 2022-10-23 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:16:16 |
Package Statistics | |
---|---|
Total Downloads: | 122 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 4 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Open your module's model (e.g. /Models/Shop.php
) and implement \Neonbug\Gallery\Traits\GalleryImagesTraitInterface
interface.
Example:
<?php namespace App\Packages\Shop\Models;
class Shop extends \Neonbug\Common\Models\BaseModel implements \Neonbug\Gallery\Traits\GalleryImagesTraitInterface {
public $gallery_images = []; // keys are id languages, then field names
public static function getTableNameForGalleryImages() { return 'shop'; } // from GalleryImagesTraitInterface
public static function getUploadsFolderNameForGalleryImages() { return 'shop'; } // from GalleryImagesTraitInterface
Use trait \Neonbug\Gallery\Traits\GalleryImagesTrait
in your module's ServiceProvider (e.g. /Providers/ServiceProvider.php
.
Example:
<?php namespace App\Packages\Shop\Providers;
class ServiceProvider extends \Neonbug\Common\Providers\BaseServiceProvider {
use \Neonbug\Gallery\Traits\GalleryImagesTrait;
Add a field (or multiple) with type gallery_admin::add_fields.gallery_images
in your module's config file (e.g. /config/shop.php
).
Example:
<?php
return [
...
'add' => [
[
'name' => 'images',
'type' => 'gallery_admin::add_fields.gallery_images',
'value' => '',
],
],
...
];
To load images, use getImages
method on GalleryRepository
. It returns a collection of GalleryImage
objects.
Example:
<?php
...
$images = App::make('\Neonbug\Gallery\Repositories\GalleryRepository')->getImages(
'shop', // table name
'images', // field name
$item->id_shop, // item id
null // language id (or null, if this field is language independent)
);
To display images in views, use getPath
method on GalleryImage
to get the image path.
Example:
@foreach ($images as $image)
<?php
$image_path = $image->getPath(
'shop', // table name
'images', //
$item->id_shop, // item id
0 // language id (or 0, if this field is language independent)
);
if (!file_exists($image_path))
{
continue;
}
?>
<img src="{!! Croppa::url($image_path, 420, 280) !!}" />
@endforeach
Available under the MIT license.