承接 mar3y/image-upload 相关项目开发

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

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

mar3y/image-upload

最新稳定版本:v1.0.0

Composer 安装命令:

composer require mar3y/image-upload

包简介

A package for handling image uploads in Laravel applications.

README 文档

README

A Laravel package for handling image uploads in your applications.

Installation

You can install the package via composer:

composer require mar3y/image-upload

Usage

Using the HasImage Trait

To use the HasImage trait in your model, follow these steps:

  1. Add the trait to your model class:

    use mar3y\ImageUpload\Traits\HasImage;
    
    class YourModel extends Model
    {
        use HasImage;
    
        protected static $imageAttributes = ['image'];
    }
  2. Define the image attributes:

    In your model class, define the $imageAttributes property as an array of attribute names that will store image paths. For example, if your model has an image attribute, you would set protected static $imageAttributes = ['image'];.

  3. Upload an image:

    When you save a model instance with an image attribute set to an UploadedFile instance, the trait will automatically upload the image and store the path in the attribute.

    $model = new YourModel();
    $model->image = $request->file('image');
    $model->save();
  4. Retrieve the image URL:

    You can retrieve the full URL of the image using the attribute name.

    $imageUrl = $model->image;

Using the ImageUploadHelper

You can also use the ImageUploadHelper class directly:

use mar3y\ImageUpload\Helpers\ImageUploadHelper;

$path = ImageUploadHelper::uploadImage($file, 'your-directory');

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-08