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
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-25