1. Go to this page and download the library: Download webplusm/gallery-json-media library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webplusm / gallery-json-media example snippets
use GalleryJsonMedia\JsonMedia\Concerns\InteractWithMedia;
use GalleryJsonMedia\JsonMedia\Contracts\HasMedia;
class Page extends Model implements HasMedia
{
use HasFactory;
use InteractWithMedia;
protected $casts =[
'images' => 'array',
'documents' => 'array',
];
// for auto-delete media thumbnails
protected function getFieldsToDeleteMedia(): array {
return ['images','documents'];
}
...
}
use GalleryJsonMedia\Form\JsonMediaGallery;
JsonMediaGallery::make('images')
->directory('page')
->reorderable()
->preserveFilenames()
->acceptedFileTypes()
->visibility() // only public for now - NO S3
->maxSize(4 * 1024)
->minSize()
->maxFiles()
->minFiles()
->replaceNameByTitle() // If you want to show title (alt customProperties) against file name
->image() // only images by default , u need to choose one (images or document)
->document() // only documents (eg: pdf, doc, xls,...)
->downloadable()
->deletable()
->withCustomProperties(
customPropertiesSchema: [
...
],
editCustomPropertiesOnSlideOver: true,
editCustomPropertiesTitle: "Edit customs properties")
use GalleryJsonMedia\Tables\Columns\JsonMediaColumn;
JsonMediaColumn::make('images')
->avatars(bool|Closure)
use GalleryJsonMedia\Infolists\JsonMediaEntry;
use GalleryJsonMedia\Infolists\JsonDocumentsEntry;
JsonMediaEntry::make('images')
->avatars()
->thumbHeight(100)
->thumbWidth(100)
->visible(static fn(array|null $state)=> filled($state))
// or for Documents, you can download them here
GalleryJsonMedia\Infolists\JsonDocumentsEntry::make('documents')
->columns(4)
->columnSpanFull()