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:
-
Add the trait to your model class:
use mar3y\ImageUpload\Traits\HasImage; class YourModel extends Model { use HasImage; protected static $imageAttributes = ['image']; }
-
Define the image attributes:
In your model class, define the
$imageAttributesproperty as an array of attribute names that will store image paths. For example, if your model has animageattribute, you would setprotected static $imageAttributes = ['image'];. -
Upload an image:
When you save a model instance with an image attribute set to an
UploadedFileinstance, the trait will automatically upload the image and store the path in the attribute.$model = new YourModel(); $model->image = $request->file('image'); $model->save();
-
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
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-08