1. Go to this page and download the library: Download ewk/moonshine-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/ */
ewk / moonshine-media example snippets
use Ewk\Cms\Media\MoonShine\Pages\MediaLibraryPage;
use MoonShine\MenuManager\MenuItem;
MenuItem::make(MediaLibraryPage::class, static fn (): string => __('moonshine-media::library.title'), 'photo'),
final class Tour extends Model
{
use HasMediaAttachments;
}
$tour->attachedMedia('gallery'); // Collection<CmsMedia>, by position
$tour->attachedMedia('cover', 'ru'); // the Russian cover
$tour->firstAttachedMedia('cover', 'ru'); // ?CmsMedia
$tour->attachedMediaByLocale('cover'); // ['ru' => …, 'en' => …]
Tour::query()->withAttachedMedia(['cover'])->get(); // four queries for any number of tours
MediaPicker::make('Логотип', 'logo')->kinds(['image', 'vector']);
MediaPicker::make('Картинка для соцсетей', 'og_image')->withoutDescription();
use Ewk\Cms\Media\MoonShine\Concerns\InteractsWithMediaAttachments;
use Ewk\Cms\Media\MoonShine\Fields\MediaAttachmentsField;
final class VenueResource extends ModelResource
{
use InteractsWithMediaAttachments;
}
// the form page
MediaAttachmentsField::make('Логотип', 'logo'),
MediaAttachmentsField::make('Галерея', 'gallery')->multiple()->max(6),
MediaAttachmentsField::make('Обложка', 'cover')->locale('ru')->kinds(['image']),
// its rules
...$this->getResource()->mediaAttachmentRules('cover', 'ru',
use Ewk\Cms\Media\MoonShine\Library\UsageLinkRegistry;
$this->app->extend(UsageLinkRegistry::class, static fn (UsageLinkRegistry $links): UsageLinkRegistry => $links
->resource(Page::MORPH_ALIAS, PageResource::class)
// A closure is asked when a link is built, for a resource that is configurable.
->resource(Header::MORPH_ALIAS, static fn (): string => config('my-cms.header_resource'))
// A translation key, or a closure that answers with the caption.
->caption('page', 'my-cms::usages.page'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.