承接 shrestharikesh/laravel-media-manager 相关项目开发

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

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

shrestharikesh/laravel-media-manager

Composer 安装命令:

composer require shrestharikesh/laravel-media-manager

包简介

Easily Upload Media in laravel

README 文档

README

Easily associate your Media with Eloquent Models

Getting Started

Install the package

  • composer require shrestharikesh/laravel-media-manager

Run the migration

  • php artisan migrate

Usage

Use the trait given by the package into any model:

use Shrestharikesh\LaravelMediaManager\HasMedia;

class Post extends Model
{
    use HasMedia;
    // Rest of your code
}

Associate as many media as you want to the model:

$post = Post::create($data);
$post->addMedia($request->image);

Or just one to each tag of the model:

$post->addMedia($request->image)->deletePrevious();

Easily upload media to different tags:

$post->addMedia($request->featured_image)->withTag('featured');
$post->addMedia($request->thumbnail_image)->withTag('thumbnail')->withAltText('Featured Image');

Get all the associated media easily:

$post = Post::find(1);
$post->getMedia($request->featured_image); // Returns medias from all topics
$post->getMedia($request->featured_image, 'default'); // Medias uploaded without any tag
$post->getMedia($request->featured_image, 'featured');

Or just the one:

$post->getFirstMedia($request->featured_image);
$post->getFirstMedia($request->featured_image, 'featured');

Show the media easily to your blade files:

<img src="{{$featured_post->getFirstMedia('featured')?->url}}"/>

You are about to remove your model and want to remove all associated medias?

$post = Post::find(1);
$post->deleteMedia();
$post->delete();

Or just delete medias from specific topic:

$post = Post::find(1);
$post->deleteMedia('featured');

Maybe just the one you don't need anymore:

$post->deleteSpecificMedia(1); // Pass the media id

Oh no! you've found bugs? Feel free to create an issue on GitHub, we'll fix it ASAP.

License

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

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-25