定制 gterrusa/frontendmedialibrary 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

gterrusa/frontendmedialibrary

最新稳定版本:1.1.4

Composer 安装命令:

composer require gterrusa/frontendmedialibrary

包简介

:package_description

README 文档

README

Latest Version on Packagist Total Downloads Build Status StyleCI

FrontendMedialibrary is a trait that makes the media, on your Laravel models that use Spatie Medialibrary, more easily accessible in frontend frameworks. Take a look at contributing.md to see a to do list.

Installation

Via Composer

$ composer require gterrusa/frontendmedialibrary

Usage

Set up your Model

/**
 * Model must be using Spatie Medialibrary
 */

class User extends Model implements HasMedia
{
    use InteractsWithMedia, HasFrontendMedia;
    
    // If you would like the frontendMedia attribute included with your model automatically
    protected $appends = ['frontendMedia'];
    
    
    /**
     * Spatie medialibrary media collections
     * any media collections can be set up here
     * this is just an example.
     */
    public function registerMediaCollections(): void
    {
        $this->addMediaCollection('avatar')->singleFile();

        $this->addMediaCollection('user_gallery');
    }

    /**
     * Spatie medialibrary media conversions
     * any media conversions can be set up here
     * this is just an example
     */
    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('optimized')
            ->fit(Manipulations::FIT_MAX, 1500, 1500);

        $this->addMediaConversion('thumb')
            ->fit(Manipulations::FIT_MAX, 250, 250);
    }
}

Example Result:

** HasFrontendMedia will pick up all of your registered collections, conversions, and custom properties automatically. They do not have to be these exact ones. This is just an example of the structure of the output.

>>> $user->frontendMedia;
=> Illuminate\Support\Collection {#4382
     all: [
       "avatar" => Illuminate\Support\Collection {#4439
         all: [
           [
             "src" => "http://frontend-medialibrary.local/storage/1/41301408.jpeg",
             "conversions" => Illuminate\Support\Collection {#4425
               all: [
                 "thumb" => "http://frontend-medialibrary.local/storage/1/conversions/41301408-thumb.jpg",
                 "optimized" => "http://frontend-medialibrary.local/storage/1/conversions/41301408-optimized.jpg",
               ],
             },
             "custom_properties" => Illuminate\Support\Collection {#4384
               all: [
                 "alt" => "my alt tag",
               ],
             },
           ],
         ],
       },
       "user_gallery" => Illuminate\Support\Collection {#4469
         all: [
           [
             "src" => "http://frontend-medialibrary.local/storage/2/49268400_10155665639226152_4845558111659884544_n.jpg",
             "conversions" => Illuminate\Support\Collection {#4443
               all: [
                 "thumb" => "http://frontend-medialibrary.local/storage/2/conversions/49268400_10155665639226152_4845558111659884544_n-thumb.jpg",
                 "optimized" => "http://frontend-medialibrary.local/storage/2/conversions/49268400_10155665639226152_4845558111659884544_n-optimized.jpg",
               ],
             },
             "custom_properties" => Illuminate\Support\Collection {#4456
               all: [],
             },
           ],
           [
             "src" => "http://frontend-medialibrary.local/storage/3/68544499_10156079858431152_5954628979427115008_n.jpg",
             "conversions" => Illuminate\Support\Collection {#4444
               all: [
                 "thumb" => "http://frontend-medialibrary.local/storage/3/conversions/68544499_10156079858431152_5954628979427115008_n-thumb.jpg",
                 "optimized" => "http://frontend-medialibrary.local/storage/3/conversions/68544499_10156079858431152_5954628979427115008_n-optimized.jpg",
               ],
             },
             "custom_properties" => Illuminate\Support\Collection {#4470
               all: [],
             },
           ],
         ],
       },
     ],
   }

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

license. Please see the license file for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固