### Install Package Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Install the package using Composer. Then, publish the package's assets using Artisan. ```bash composer require ebess/advanced-nova-media-library ``` ```bash php artisan vendor:publish --tag=nova-media-library ``` -------------------------------- ### Install Advanced Nova Media Library Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Install the package via Composer and publish its configuration file. ```bash composer require ebess/advanced-nova-media-library php artisan vendor:publish --tag=nova-media-library ``` -------------------------------- ### Configure Nova Resource with Media Fields Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt This example demonstrates how to define a Nova resource with various media fields. It includes configurations for single and multiple images, video uploads, and generic file attachments, showcasing features like conversion definitions, validation rules, cropping, custom properties, and allowed file types. ```php sortable(), Text::make('Title'), // Single required hero image with thumbnail conversion Images::make('Hero Image', 'hero') ->conversionOnIndexView('thumb') ->conversionOnDetailView('thumb') ->conversionOnForm('thumb') ->rules('required') ->croppingConfigs(['aspectRatio' => 16 / 9]) ->mustCrop(), // Multi-image gallery with custom properties and existing media support Images::make('Gallery', 'gallery') ->conversionOnPreview('medium-size') ->conversionOnIndexView('thumb') ->fullSize() ->singleImageRules('dimensions:min_width=200') ->showStatistics() ->enableExistingMedia() ->customPropertiesFields([ Boolean::make('Active'), Text::make('Alt Text'), ]), // Video field with thumbnail extraction Media::make('Video', 'video') ->conversionOnIndexView('thumb') ->singleMediaRules('max:51200') ->setAllowedFileTypes(['video/mp4', 'video/webm']), // Generic file attachments with programmatic custom properties Files::make('Attachments', 'attachments') ->customProperties(['uploaded_by' => auth()->id()]) ->temporary(now()->addMinutes(15)), ]; } } ``` -------------------------------- ### Model Setup for Media Library Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Configure Spatie Media Library collections and conversions on your Eloquent model. This includes defining media conversion sizes and registering different media collection types like single-file, multi-file, and generic attachments. ```php use Spatie obyl use Spatie obyl use Spatie obyl class Article extends Model implements HasMedia { use InteractsWithMedia; public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb') ->width(130) ->height(130); $this->addMediaConversion('medium-size') ->width(800); } public function registerMediaCollections(): void { $this->addMediaCollection('hero')->singleFile(); // single-file collection $this->addMediaCollection('gallery'); // multi-file collection $this->addMediaCollection('attachments'); // generic files } } ``` -------------------------------- ### Configuration Reference Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Reference for the config/nova-media-library.php file. Adjust settings like default cropping, existing media picker, and hidden collections. ```php // config/nova-media-library.php return [ // Enable/disable image cropping for all Images fields by default 'default-croppable' => true, // Enable the existing-media picker endpoint and UI 'enable-existing-media' => false, // Collections excluded from the existing-media search results 'hide-media-collections' => [], ]; ``` -------------------------------- ### Configure Video Uploads with Media::make() Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Use Media::make() for video uploads, enabling auto-generated thumbnail conversions. Set single media upload rules to manage file size limits. ```php use Ebess\AdvancedNovaMediaLibrary\Fields\Media; // In Nova Resource public function fields(Request $request): array { return [ Media::make('Video Gallery', 'videos') ->conversionOnIndexView('thumb') ->singleMediaRules('max:50000'), // max 50 MB per file ]; } // In Eloquent Model — extract a frame for the thumbnail conversion public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb') ->width(368) ->height(232) ->extractVideoFrameAtSecond(1); } ``` -------------------------------- ### Enable Responsive Image Generation with withResponsiveImages() Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Trigger Spatie Media Library's responsive image feature to automatically generate multiple sized variants of uploaded images. ```php Images::make('Hero', 'hero') ->withResponsiveImages(); ``` -------------------------------- ### API Endpoint: List Existing Media Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Lists existing media for the existing-media picker. Protected by Nova middleware, supports full-text search and pagination. Returns a JSON resource collection. ```bash # Search media by name, paginated at 12 per page curl -X GET \ "https://your-app.test/nova-vendor/ebess/advanced-nova-media-library/media?search_text=logo&per_page=12&page=1" \ -H "Accept: application/json" \ -H "X-CSRF-TOKEN: " ``` ```json # Example JSON response { "data": [ { "id": 42, "model_type": "App\\Models\\Article", "model_id": 7, "collection_name": "gallery", "name": "company-logo", "file_name": "company-logo.png", "mime_type": "image/png", "size": 24832, "__media_urls__": { "__original__": "https://your-app.test/storage/42/company-logo.png", "indexView": "https://your-app.test/storage/42/conversions/company-logo-thumb.jpg", "detailView": "", "form": "", "preview": "" } } ], "links": { "first": "...", "last": "...", "prev": null, "next": "..." }, "meta": { "current_page": 1, "per_page": 12, "total": 38 } } ``` -------------------------------- ### Enable Existing Media Selection Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md To enable the selection of existing media, publish the configuration files and set 'enable-existing-media' to true in the config file. Then, enable the feature for the specific field using enableExistingMedia(). ```bash artisan vendor:publish --tag=nova-media-library ``` ```php return [ 'enable-existing-media' => true, ]; ``` ```php Images::make('Image')->enableExistingMedia(), ``` -------------------------------- ### Display Media Statistics with showStatistics() Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Render file size, pixel dimensions, and MIME type badges below each image in the gallery for quick reference. ```php Images::make('Gallery', 'gallery') ->showStatistics(); ``` -------------------------------- ### Model Media Configuration Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Configure your Eloquent model to register media conversions and collections using Spatie's Media Library traits. ```php use Spatie\MediaLibrary\MediaCollections\Models\Media; public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb') ->width(130) ->height(130); } public function registerMediaCollections(): void { $this->addMediaCollection('main')->singleFile(); $this->addMediaCollection('my_multi_collection'); } ``` -------------------------------- ### List Existing Media Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Lists existing media for the existing-media picker. Protected by Nova middleware. Supports full-text search and pagination. Returns a JSON resource collection. ```APIDOC ## API Endpoint: `GET /nova-vendor/ebess/advanced-nova-media-library/media` Lists existing media for the existing-media picker. Protected by Nova middleware. Supports full-text search and pagination. Returns a JSON resource collection. ```bash # Search media by name, paginated at 12 per page curl -X GET \ "https://your-app.test/nova-vendor/ebess/advanced-nova-media-library/media?search_text=logo&per_page=12&page=1" \ -H "Accept: application/json" \ -H "X-CSRF-TOKEN: " # Example JSON response { "data": [ { "id": 42, "model_type": "App\\Models\\Article", "model_id": 7, "collection_name": "gallery", "name": "company-logo", "file_name": "company-logo.png", "mime_type": "image/png", "size": 24832, "__media_urls__": { "__original__": "https://your-app.test/storage/42/company-logo.png", "indexView": "https://your-app.test/storage/42/conversions/company-logo-thumb.jpg", "detailView": "", "form": "", "preview": "" } } ], "links": { "first": "...", "last": "...", "prev": null, "next": "..." }, "meta": { "current_page": 1, "per_page": 12, "total": 38 } } ``` ``` -------------------------------- ### Enable Responsive Images Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Integrate responsive image functionality by calling withResponsiveImages() on the field. This leverages the Spatie MediaLibrary's responsive images feature. ```php Images::make('Image 1', 'img1') ->withResponsiveImages(); ``` -------------------------------- ### Nova Resource: Multiple Images with Ordering Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Configure the `Images::make()` field for multiple image uploads within a collection that allows it. This enables gallery mode with drag-and-drop reordering. You can set specific conversion for previews, define collection-level validation rules (e.g., maximum number of images), and apply per-image validation rules. ```php Images::make('Gallery', 'gallery') ->conversionOnPreview('medium-size') // "lightbox" preview conversion ->conversionOnDetailView('thumb') ->conversionOnIndexView('thumb') ->conversionOnForm('thumb') ->fullSize() // field spans full column width ->rules('required', 'size:3') // collection-level rules (max 3 images) ->singleImageRules('dimensions:min_width=100'), // per-image validation ``` -------------------------------- ### Enable Reuse of Existing Media Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Allows users to search and copy already-uploaded media items to new models without re-uploading. Must be enabled in the config file first. ```php // config/nova-media-library.php return [ 'enable-existing-media' => true, 'hide-media-collections' => ['temp', 'private'], // exclude these from the picker ]; ``` ```php // In your Nova resource Images::make('Gallery', 'gallery') ->enableExistingMedia(); ``` -------------------------------- ### Generate Signed Temporary URLs with temporary() Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Create time-limited signed URLs for media stored on S3 with private ACL. This feature is incompatible with the existing-media feature. ```php use Illuminate\Support\Carbon; Images::make('Private Photos', 'private_photos') ->temporary(now()->addMinutes(5)); Files::make('Confidential Docs', 'confidential_docs') ->temporary(Carbon::now()->addMinutes(30)); ``` -------------------------------- ### Control Image Cropping with Images::make() Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Manage image cropping behavior for Images fields. Disable cropping, enforce aspect ratios, or require users to crop before acceptance. ```php // Disable cropping for a specific field Images::make('Avatar', 'avatar') ->croppable(false); ``` ```php // Enforce a fixed aspect ratio Images::make('Banner', 'banner') ->croppingConfigs(['aspectRatio' => 16 / 9]); ``` ```php // Force the user to crop before the image is accepted Images::make('Profile Photo', 'profile_photo') ->mustCrop() ->croppingConfigs(['aspectRatio' => 1]); // square crop ``` ```php // Disable cropping globally via config/nova-media-library.php return [ 'default-croppable' => false, ]; ``` -------------------------------- ### Enable Laravel Vapor (S3 Direct Upload) Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Enables client-side direct uploads to S3 via Laravel Vapor pre-signed URLs, bypassing the Nova server for large files. This is useful for improving upload performance and reducing server load. ```php Images::make('Gallery', 'gallery') ->uploadsToVapor(); Files::make('Large Files', 'large_files') ->uploadsToVapor() ->setMaxFileSize(102400); // 100 MB ``` -------------------------------- ### Show Image Statistics Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Use this to display image statistics such as size, dimensions, and type directly in the Nova interface. ```php Images::make('Gallery') ->showStatistics(); ``` -------------------------------- ### Reuse Existing Media Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Allows users to search and copy already-uploaded media items to new models without re-uploading using `enableExistingMedia()`. Must be enabled in the config file first. ```APIDOC ## `enableExistingMedia()` — Reuse Existing Media Across Models Allows users to search and copy already-uploaded media items to new models without re-uploading. Must be enabled in the config file first. ```php // config/nova-media-library.php return [ 'enable-existing-media' => true, 'hide-media-collections' => ['temp', 'private'], // exclude these from the picker ]; ``` ```php // In your Nova resource Images::make('Gallery', 'gallery') ->enableExistingMedia(); ``` ``` -------------------------------- ### Nova Resource: Generic File Management Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Utilize the `Files::make()` field for managing any type of file (PDFs, documents, archives, etc.). This field inherits capabilities from the `Images` field but removes the default image MIME restriction and can be configured to hide from the index view. It also supports custom fields for per-file properties. ```php use Ebess\AdvancedNovaMediaLibrary\Fields\Files; // Single file Files::make('Contract PDF', 'one_file'), // Multiple files with custom properties Files::make('Attachments', 'attachments') ->customPropertiesFields([ \Laravel\Nova\Fields\Boolean::make('Active'), \Laravel\Nova\Fields\Text::make('Description'), ]), ``` -------------------------------- ### Customize File Naming with setFileName() and setName() Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Override the stored filename and media name using callbacks. Callbacks receive original filename, extension, and the model. ```php // Store files as MD5 hash of the original name Images::make('Product Image', 'product_image') ->setFileName(function (string $originalFilename, string $extension, $model): string { return md5($originalFilename) . '.' . $extension; }) ->setName(function (string $originalFilename, $model): string { return $model->name . ' — product image'; }); ``` ```php // Slugify model name as the filename Images::make('Cover', 'cover') ->setFileName(function (string $originalFilename, string $extension, $model): string { return \Illuminate\Support\Str::slug($model->title) . '.' . $extension; }); ``` -------------------------------- ### Configure Image Cropping Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Customize cropping configurations, such as the aspect ratio, using the croppingConfigs method. Refer to the vue-js-clipper documentation for available options. ```php Images::make('Gallery')->croppingConfigs(['aspectRatio' => 4/3]); ``` -------------------------------- ### Set Programmatic Custom Properties with customProperties() Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Set hidden, programmatic custom properties on media items. These are not shown to the user and can be used for internal tracking or metadata. ```php // Programmatic custom properties (not shown to user) Files::make('Documents', 'documents') ->customProperties([ 'uploaded_by' => auth()->id(), 'source' => 'admin-panel', ]); ``` -------------------------------- ### Add Editable Custom Properties with customPropertiesFields() Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Allow users to edit custom properties for each media item using Nova fields. These are rendered in a modal per media item. ```php use Laravel\Nova\Fields\Boolean; use Laravel\Nova\Fields\Markdown; use Laravel\Nova\Fields\Text; // User-editable custom properties — rendered in a modal per media item Images::make('Gallery', 'gallery') ->customPropertiesFields([ Boolean::make('Active'), Text::make('Alt Text'), Markdown::make('Caption'), ]); ``` -------------------------------- ### Set Custom HTTP Headers Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Configure custom HTTP headers for media uploads. This is useful for setting specific metadata or authorization tokens. ```php Images::make('Gallery') ->customHeaders([ 'header-name' => 'header-value', ]); ``` -------------------------------- ### Laravel Vapor (S3 Direct Upload) Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Enables client-side direct uploads to S3 via Laravel Vapor pre-signed URLs, bypassing the Nova server for large files using `uploadsToVapor()`. ```APIDOC ## `uploadsToVapor()` — Laravel Vapor (S3 Direct Upload) Enables client-side direct uploads to S3 via Laravel Vapor pre-signed URLs, bypassing the Nova server for large files. ```php Images::make('Gallery', 'gallery') ->uploadsToVapor(); Files::make('Large Files', 'large_files') ->uploadsToVapor() ->setMaxFileSize(102400); // 100 MB ``` ``` -------------------------------- ### Custom Media Serialization Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Override how media models are serialized to JSON for the frontend. Useful for appending or restricting fields in the media output. ```php Images::make('Gallery', 'gallery') ->serializeMediaUsing(function (SpatieSSMediaLibrarySModelsSMedia $media): array { return [ 'id' => $media->id, 'name' => $media->name, 'file_name' => $media->file_name, 'mime_type' => $media->mime_type, 'size' => $media->human_readable_size, 'custom' => $media->getCustomProperty('alt_text'), ]; }); ``` -------------------------------- ### Multiple Image Upload Field with Ordering Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Set up the `Images` field for multiple image uploads, enabling drag-and-drop ordering. Configure various conversion types, validation rules, and specific image rules. ```php use Ebess\AdvancedNovaMediaLibrary\Fields\Images; public function fields(Request $request) { return [ Images::make('Images', 'my_multi_collection') // second parameter is the media collection name ->conversionOnPreview('medium-size') // conversion used to display the "original" image ->conversionOnDetailView('thumb') // conversion used on the model's view ->conversionOnIndexView('thumb') // conversion used to display the image on the model's index page ->conversionOnForm('thumb') // conversion used to display the image on the model's form ->fullSize() // full size column ->rules('required', 'size:3') // validation rules for the collection of images // validation rules for the collection of images ->singleImageRules('dimensions:min_width=100'), ]; } ``` -------------------------------- ### Custom Media Serialization Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Override how media models are serialized to JSON for the frontend using `serializeMediaUsing()`. Useful for appending or restricting fields. ```APIDOC ## `serializeMediaUsing()` — Custom Media Serialization Override how media models are serialized to JSON for the frontend. Useful for appending or restricting fields. ```php Images::make('Gallery', 'gallery') ->serializeMediaUsing(function (\Spatie\MediaLibrary\MediaCollections\Models\Media $media): array { return [ 'id' => $media->id, 'name' => $media->name, 'file_name' => $media->file_name, 'mime_type' => $media->mime_type, 'size' => $media->human_readable_size, 'custom' => $media->getCustomProperty('alt_text'), ]; }); ``` ``` -------------------------------- ### Set Max File Size and Allowed File Types Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Enforce file size (in kilobytes) and MIME type restrictions client-side before the upload begins. Use this to validate user uploads. ```php Media::make('Videos', 'videos') ->setMaxFileSize(51200) // 50 MB ->setAllowedFileTypes(['video/mp4', 'video/webm']); Images::make('Profile Photo', 'profile_photo') ->setMaxFileSize(2048) // 2 MB ->setAllowedFileTypes(['image/jpeg', 'image/png']); ``` -------------------------------- ### Define Custom Properties Fields Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Add custom fields for media properties using customPropertiesFields. This allows users to input additional data when uploading media. ```php Images::make('Gallery') ->customPropertiesFields([ Boolean::make('Active'), Markdown::make('Description'), ]); ``` ```php Files::make('Multiple files', 'multiple_files') ->customPropertiesFields([ Boolean::make('Active'), Markdown::make('Description'), ]); ``` -------------------------------- ### Media Field for Videos Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Utilize the `Media` field instead of `Images` to handle video uploads. Configure thumbnail conversions and set validation rules. ```php use Ebess\AdvancedNovaMediaLibrary\Fields\Media; class Category extends Resource { public function fields(Request $request) { Media::make('Gallery') // media handles videos ->conversionOnIndexView('thumb') ->singleMediaRules('max:5000'); // max 5000kb } } ``` ```php use Spatie\MediaLibrary\MediaLibrary as Media; class YourModel extends Model implements HasMedia { public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb') ->width(368) ->height(232) ->extractVideoFrameAtSecond(1); } } ``` -------------------------------- ### API Endpoint: Download Media Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Downloads a media file by ID, validated with a UUID parameter to prevent enumeration attacks. Ensure the UUID is correctly provided to access the file. ```bash curl -X GET \ "https://your-app.test/nova-vendor/ebess/advanced-nova-media-library/download/42?uuid=550e8400-e29b-41d4-a716-446655440000" \ -H "Accept: application/octet-stream" \ --output downloaded-file.png ``` -------------------------------- ### Nova Resource: Single Image Upload Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Use the `Images::make()` field in a Nova resource for uploading single image files. It maps to a Spatie media collection and enforces image MIME validation by default. You can specify conversion types for different views (index, detail, form) and apply standard Laravel validation rules. ```php use Ebess\AdvancedNovaMediaLibrary\Fields\Images; use Illuminate\Http\Request; // In your Nova Resource (e.g. app/Nova/Article.php) public function fields(Request $request): array { return [ Images::make('Hero Image', 'hero') // 'hero' = media collection name ->conversionOnIndexView('thumb') // thumbnail shown in resource index ->conversionOnDetailView('thumb') // image shown on detail view ->conversionOnForm('thumb') // image shown in edit form ->rules('required'), // standard Laravel validation ]; } ``` -------------------------------- ### Add Custom Upload Headers with customHeaders() Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Append arbitrary HTTP headers to media upload requests. Useful for cache control or content disposition directives. ```php Images::make('Gallery', 'gallery') ->customHeaders([ 'Cache-Control' => 'max-age=86400', 'Content-Disposition' => 'inline', ]); ``` -------------------------------- ### Set Custom Properties Without User Input Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Set custom properties directly using the customProperties method, providing key-value pairs. This is useful for setting properties programmatically. ```php Files::make('Multiple files', 'multiple_files') ->customProperties([ 'foo' => auth()->user()->foo, 'bar' => $api->getNeededData(), ]); ``` -------------------------------- ### Generate Temporary URLs for S3 Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md When using Amazon S3, generate temporary signed URLs for media access. Specify an expiration time using a Carbon instance. ```php Images::make('Image 1', 'img1') ->temporary(now()->addMinutes(5)) ``` ```php Files::make('Multiple files', 'multiple_files') ->temporary(now()->addMinutes(10), ``` -------------------------------- ### Frontend File Restrictions Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Enforce file size (in kilobytes) and MIME type restrictions client-side before the upload begins using `setMaxFileSize()` and `setAllowedFileTypes()`. ```APIDOC ## `setMaxFileSize()` / `setAllowedFileTypes()` — Frontend File Restrictions Enforce file size (in kilobytes) and MIME type restrictions client-side before the upload begins. ```php Media::make('Videos', 'videos') ->setMaxFileSize(51200) // 50 MB ->setAllowedFileTypes(['video/mp4', 'video/webm']); Images::make('Profile Photo', 'profile_photo') ->setMaxFileSize(2048) // 2 MB ->setAllowedFileTypes(['image/jpeg', 'image/png']); ``` ``` -------------------------------- ### Generic File Upload Field Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Use the `Files` field to upload and manage generic files. Specify the field label and the media collection name. ```php use Ebess\AdvancedNovaMediaLibrary\Fields\Files; Files::make('Single file', 'one_file'), Files::make('Multiple files', 'multiple_files'), ``` -------------------------------- ### Download Media File Source: https://context7.com/ebess/advanced-nova-media-library/llms.txt Downloads a media file by ID, validated with a UUID parameter to prevent enumeration attacks. ```APIDOC ## API Endpoint: `GET /nova-vendor/ebess/advanced-nova-media-library/download/{media}` Downloads a media file by ID, validated with a UUID parameter to prevent enumeration attacks. ```bash curl -X GET \ "https://your-app.test/nova-vendor/ebess/advanced-nova-media-library/download/42?uuid=550e8400-e29b-41d4-a716-446655440000" \ -H "Accept: application/octet-stream" \ --output downloaded-file.png ``` ``` -------------------------------- ### Enforce Image Cropping on Upload Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md To ensure images are cropped upon upload, use the mustCrop() method. This is useful for enforcing specific aspect ratios or dimensions. ```php Images::make('Gallery')->mustCrop(); ``` -------------------------------- ### Disable Cropping by Default Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Set 'default-croppable' to false in the 'config/nova-media-library.php' file to disable the cropping feature by default for all images. ```php return [ 'default-croppable' => false, ]; ``` -------------------------------- ### Set Custom Name for Media Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Change the 'name' field of a Media object using the setName function. It takes a callback that receives the original filename and the model, allowing for custom naming logic. ```php Images::make('Image 1', 'img1') ->setName(function($originalFilename, $model){ return md5($originalFilename); }); ``` -------------------------------- ### Set Custom Filename for Uploaded Images Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Customize the filename of uploaded images using the setFileName function, which accepts a callback. The callback receives the original filename, extension, and the model, allowing dynamic filename generation. ```php Images::make('Image 1', 'img1') ->setFileName(function($originalFilename, $extension, $model){ return md5($originalFilename) . '.' . $extension; }); ``` ```php Images::make('Image 2', 'img2') ->setFileName(function($originalFilename, $extension, $model){ return str_slug($model->name) . '.' . $extension; }); ``` -------------------------------- ### Single Image Upload Field Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md Configure the `Images` field for single image uploads. Specify the media collection name, conversion for the index view, and validation rules. ```php use Ebess\AdvancedNovaMediaLibrary\Fields\Images; public function fields(Request $request) { return [ Images::make('Main image', 'main') // second parameter is the media collection name ->conversionOnIndexView('thumb') // conversion used to display the image ->rules('required'), // validation rules ]; } ``` -------------------------------- ### Disable Image Cropping Source: https://github.com/ebess/advanced-nova-media-library/blob/master/readme.md To disable the image cropping feature, use the croppable(false) method on the field. This prevents users from cropping images. ```php Images::make('Gallery')->croppable(false); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.