moh-slimani/media
Composer 安装命令:
composer require moh-slimani/media
包简介
A Media Model for laravel medialibrary
README 文档
README
This package simplifies the integration of Spatie MediaLibrary by offering a streamlined approach to registering and managing media assets within Laravel applications, effortlessly cast media to a simple format, leveraging a path generator that enhances readability and organization. Seamlessly handle media registration while maintaining all functionalities of The MediaLibrary package.
Installation
You can install the package via composer:
composer require moh-slimani/media
You must publish and run the migrations,this will add soft delete to the media model
php artisan vendor:publish --tag="media-migrations"
php artisan migrate
change the media_model in the media library config file
config/media-library.php
... /* * The fully qualified class name of the media model. */ 'media_model' => MohSlimani\Media\Models\Media::class, ...
Optional : you can change the path generator in the media library config file
... /* * The class that contains the strategy for determining a media file's path. */ 'path_generator' => MohSlimani\Media\Helpers\MediaPathGenerator::class, ...
Usage
use MohSlimani\Media\Traits\UseMediaModel use MohSlimani\Media\Media use Spatie\MediaLibrary\HasMedia; class User extends Authenticatable implements HasMedia { // you don't need to user InteractsWithMedia use HasApiTokens, HasFactory, Notifiable, UseMediaModel; /** * This array should contain the list of media keys to be registered. * * @var array $files * @example ['photo' => Media::SINGLE_FILE, 'files' => Media::MULTIPLE_FILES] */ protected array $files = [ 'photo' => Media::SINGLE_FILE, 'cv', // Media::SINGLE_FILE is the default 'files' => Media::MULTIPLE_FILES ]; ...
After that you can add files it like you used to using the medialibrary package
/** @var File $photo */ $user->addMedia($photo)->toMediaCollection('photo'); // Or use the included function $user->addMediaFiles($photo, 'photo');
the function addMediaFiles to simplify the process of adding media files to collections. This function allows you to add a single file to a specified collection and provides an option to keep or delete existing files in the collection. it will also generate a unique code based on current time to prepend to the file name You can find more information about this and other changes in the CHANGELOG.
you can get the files like this
$user->photo [ "id" => 15, "name" => "IMG_7833", "url" => "http://media.test/storage/Users/1/photo/IMG_7833.jpg", "size" => 249686, "mime" => "image/jpeg", "type" => "image", "created_at" => Illuminate\Support\Carbon @1705898712 {#6527 date: 2024-02-19 00:00:00.0 UTC (+00:00), }, "updated_at" => Illuminate\Support\Carbon @1705898712 {#6782 date: 2024-02-19 00:00:00.0 UTC (+00:00), }, ]
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
moh-slimani/media 适用场景与选型建议
moh-slimani/media 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 42 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「media」 「laravel」 「Mohamed slimani」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moh-slimani/media 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moh-slimani/media 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moh-slimani/media 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
Laravel Media Popup to upload/view the files
This field give the ability to hide fields from your resources table on mobile screens for a better responsive concept
A wrapper package over spatie query builder package to simplify filters creation for Laravel Apps
This is my package laravel-oci-driver
Asset Manager Laravel package for Gigcodes UI Library
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-19