behzadsp/eloquent-dynamic-photos
Composer 安装命令:
composer require behzadsp/eloquent-dynamic-photos
包简介
A Laravel Eloquent trait for dynamically handling and managing photo storage with ease.
README 文档
README
This is a Laravel Eloquent trait that provides an easy and dynamic way to manage photos in your Eloquent models.
Installation
You can install the package via composer:
composer require behzadsp/eloquent-dynamic-photos
You can publish the config file with:
php artisan vendor:publish --provider="Behzadsp\EloquentDynamicPhotos\Providers\EloquentDynamicPhotosServiceProvider"
This is the contents of the global configurations for uploading images.
<?php return [ 'disk' => 'public', // Disk to use for storing photos 'root_directory' => 'images', // Root directory for photos 'name_attribute' => 'slug', // Model attribute used for file name 'quality' => 50, // Quality for encoding the photos 'format' => 'webp', // Format of the stored photos 'slug_limit' => 240, // Name limit to save in database 'timestamp_format' => 'U', // U represents Unix timestamp ];
Usage
After installing the package, simply use the HasPhotos trait in your Eloquent models:
use Behzadsp\EloquentDynamicPhotos\Traits\HasPhotos; class YourModel extends Model { use HasPhotos; // ... }
Of course, you can override certain config in individual model by declaring the corresponding method. Like below:
class User extends Model { use HasPhotos; protected function eloquentPhotoDisk() { return 'user-avatar'; } protected function eloquentPhotoFormat() { return 'png'; } protected function eloquentPhotoRootDirectory() { return 'images'; } protected function eloquentPhotoQuality() { return '50'; } protected function eloquentPhotoNameAttribute() { return 'slug'; } protected function eloquentPhotoSlugLimit() { return '240'; } protected function eloquentPhotoTimestampFormat() { return 'U'; } }
You can now use the methods provided by the trait in your models:
$model = YourModel::first(); // delete photo file only and not database column. $model->deletePhotoFile('photo_field'); // update photo file and save it to database column. $model->updatePhoto($photo, 'photo_field'); // get full photo path $model->getPhotoFullPath('photo_path'); // get photo directory path $model->getPhotoDirectoryPath(); // get photo URL $model->photo_field_url;
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
behzadsp/eloquent-dynamic-photos 适用场景与选型建议
behzadsp/eloquent-dynamic-photos 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 51 次下载、GitHub Stars 达 22, 最近一次更新时间为 2023 年 07 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「dynamic」 「photo」 「eloquent」 「behzadsp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 behzadsp/eloquent-dynamic-photos 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 behzadsp/eloquent-dynamic-photos 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 behzadsp/eloquent-dynamic-photos 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Flexslider slideshow content block for Silverstripe Elemental
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Glance project service for managing user photos
EAV modeling package for Eloquent and Laravel.
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Write down your routing mapping at one place
统计信息
- 总下载量: 51
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-14