behzadsp/eloquent-dynamic-photos 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

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

Latest Version on Packagist Total Downloads

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 behzadsp/eloquent-dynamic-photos 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 22
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-14