themightysapien/medialibrary 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

themightysapien/medialibrary

最新稳定版本:1.3.12

Composer 安装命令:

composer require themightysapien/medialibrary

包简介

Media Library on top of spatie media package. Helps to resuse uploaded media.

README 文档

README

Latest Version on Packagist Total Downloads GitHub Actions

This packages adds a reusable library functionality on top of Spatie Media Library package.

Features

  • Add media to library
  • Use media from library
  • Add media through library
  • Clear library

Installation

You can install the package via composer:

composer require themightysapien/medialibrary
# publish config and migrations
php artisan vendor:publish --provider="Themightysapien\MediaLibrary\MediaLibraryServiceProvider" --tag="config" --tag="migrations"
# Check config files for any modifications then run
php artisan migrate

Prepare Your Model

Just add InteractsWithMediaLibrary trait on top of spatie's model setup.

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Themightysapien\MediaLibrary\Traits\InteractsWithMediaLibrary;

class YourModel extends Model implements HasMedia
{
    use InteractsWithMedia;
    use InteractsWithMediaLibrary;
}

Usage

Add Media to library

use Themightysapien\MediaLibrary\Facades\MediaLibrary;

$media = MediaLibrary::open($user_id)->addMedia($file);

Associate file for model through library.

This will first add the file to library and then associate media to the model.

$model->addMediaThroughLibrary($file, $user_id)
// chain through any spatie's File Adder functions
->toMediaCollection();

Associate library media for model.

$model->addMediaFromLibrary($media);
// chain through any spatie's File Adder functions
->toMediaCollection();

Clear Library

use Themightysapien\MediaLibrary\Facades\MediaLibrary;

MediaLibrary::clear($user_id);

Get library media collection

use Themightysapien\MediaLibrary\Facades\MediaLibrary;

// All Media
MediaLibrary::allMedia($user_id);

// Builder
MediaLibrary::query($user_id)->limit(5)->lastest()->get();

Get library media collection through api

$response = $this->json('GET', '{PREFIX_FROM_CONFIG}/tsmedialibrary', [
    'name' => 'document', // matches file and name with document
    'type' => 'pdf', //matches mime type with pdf
    'sort_by' => 'created_at',
    'sort_type' => 'DESC',
    'per_page' => 10 // default set on config
]);

['items' => $mediaCollection, 'pagination' => $pagination] = $response;

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email themightysapien@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-03