elsayed85/nova-image-gallery-field
Composer 安装命令:
composer require elsayed85/nova-image-gallery-field
包简介
Field for Nova that allows you to upload multiple images and sort them
README 文档
README
A custom Nova field that allows multiple image upload with sorting
Features
- For Laravel Nova ^4.0
- Multiple image upload into a
spatie/laravel-medialibrarycollection. - Image sorting
- Custom Image Validation
- Drag & Drop
- Dark Mode
Installation
composer require ardenthq/nova-image-gallery-field
Requirements
Use
Note This package reuses part of the logic used on the
Laravel\Nova\Fields\TrixField to store and handle files. This means we need to follow some steps that are mentioned on the Laravel Nova docs related to adding the migrations and pruning the files.
- Define two database tables to store pending and persisted Trix uploads. To do so, create a migration with the following table definitions:
Schema::create('nova_pending_trix_attachments', function (Blueprint $table) { $table->increments('id'); $table->string('draft_id')->index(); $table->string('attachment'); $table->string('disk'); $table->timestamps(); }); Schema::create('nova_trix_attachments', function (Blueprint $table) { $table->increments('id'); $table->string('attachable_type'); $table->unsignedInteger('attachable_id'); $table->string('attachment'); $table->string('disk'); $table->string('url')->index(); $table->timestamps(); $table->index(['attachable_type', 'attachable_id']); });
- In your
app/Console/Kernel.phpfile, you should register a daily job to prune any stale attachments from the pending attachments table and storage. Laravel Nova provides the job implementation needed to accomplish this:
use Laravel\Nova\Trix\PruneStaleAttachments; $schedule->call(function () { (new PruneStaleAttachments)(); })->daily();
-
Add the
ImageGalleryFieldfield to your Nova Resource. -
Consider that the images will be stored in a
Spatie\MediaLibrary\MediaCollections\Models\Mediacollection according to the name passed as the first parameter on the fieldmakemethod or the second parameter if set. (Dont forget to register a media collection in your model) -
Use the
rules()method to define the rules used for every single image. -
Use the
rulesMessages()method to define custom validation messages for the image rules. -
Use the
help()method if you want to place "help" text inside the Drag & Drop area.
Example
<?php namespace App\Nova; use Laravel\Nova\Http\Requests\NovaRequest; use Laravel\Nova\Resource; use Ardenthq\ImageGalleryField\ImageGalleryField; final class ResourceName extends Resource { // .... public function fields(NovaRequest $request) { return [ // .... ImageGalleryField::make('Images') ->rules('mimes:jpeg,png,jpg,gif', 'dimensions:min_width=150,min_height=150', 'max:5000') ->rulesMessages([ 'mimes' => 'You must use a valid jpeg, png, jpg or gif image.', 'max' => 'The image must be less than 5MB.', 'dimensions' => 'The image must be at least 150px wide and 150px tall.', ]) ->help('Min size 150 x 150. Max filesize 5MB.'), // ... ]; } // ... }
Development
- Run
yarn nova:installandyarn installto install all the necessary dependencies for compiling the view components. - Run
yarn run dev(oryarn run watch) while making changes to the components in your local environment. - If you change the vue components, ensure to compile for production before making a PR.
Compile for production
- Run
yarn nova:installandyarn installto install all the necessary dependencies for compiling the view components. - Run
yarn run production.
Analyze the code with phpstan
composer analyse
Refactor the code with php rector
composer refactor
Format the code with php-cs-fixer
composer format
Run tests
composer test
Security
If you discover a security vulnerability within this package, please send an e-mail to security@ardenthq.com. All security vulnerabilities will be promptly addressed.
Credits
This project exists thanks to all the people who contribute.
License
elsayed85/nova-image-gallery-field 适用场景与选型建议
elsayed85/nova-image-gallery-field 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 elsayed85/nova-image-gallery-field 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 elsayed85/nova-image-gallery-field 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-08

