承接 jameslkingsley/nova-media-library 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jameslkingsley/nova-media-library

最新稳定版本:1.4.1

Composer 安装命令:

composer require jameslkingsley/nova-media-library

包简介

Laravel Nova tools for managing the Spatie media library.

README 文档

README

Attention: Please consider using this package instead, it has a lot more support for various medialibrary features, and will probably fit your needs better!

This package is designed to be used with the awesome media library package from Spatie. With this package you can add an image field for uploading single files to a resource, a generic file field for other types, and add an images field to resources to display all of their associated media.

use Kingsley\NovaMediaLibrary\Fields\Image;

Image::make('Avatar', 'avatar')
    ->usingConversion('thumb')
    ->preservingOriginal()

In this example we're defining a field called Avatar that uses the avatar collection. It's also calling usingConversion to set the thumb conversion as the image to be displayed (on detail and index). The other methods called are dynamically applied to the upload request - this lets you call any media-library method on the field..

If you want it to remove the old image before uploading the new one, be sure to make your model's media collection a single file collection.

When you want to upload a file that isn't an image, you can use the rudimentary File field included with this package. It follows the same format as registering an Image field.

use Kingsley\NovaMediaLibrary\Fields\File;

File::make('Invoice', 'invoice')

That's all there is to it! The rest of the configuration should be done in the media collection itself, such as:

public function registerMediaCollections()
{
    $this
        ->addMediaCollection('invoice')
        ->singleFile()
        ->acceptsFile(function (File $file) {
            return $file->mimeType === 'application/pdf';
        });
}

To show all media records for your resource simply add the Images field like so:

use Kingsley\NovaMediaLibrary\Fields\Images;

public function fields(Request $request)
{
    return [
        ...
        Images::make(),
    ];
}

This will automatically use the media attribute on your model (which the HasMediaTrait adds).

Note: You currently cannot create media directly from Nova.

Registering the media resource

If you'd like to use the media resource included with this package, you need to register it manually in your NovaServiceProvider in the boot method.

Nova::resources([
    \Kingsley\NovaMediaLibrary\Resources\Media::class
]);

统计信息

  • 总下载量: 46.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 40
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 40
  • Watchers: 4
  • Forks: 5
  • 开发语言: Vue

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-05