rpwebdevelopment/has-image-laravel
Composer 安装命令:
composer require rpwebdevelopment/has-image-laravel
包简介
A package for simplifying image handling on Laravel eloquent models
README 文档
README
The has-image-laravel package is designed to be a lightweight package to simplify image handling on Laravel
models, currently rather than having to handle uploaded files in your controllers, usually leading to significant
code duplication.
This package allows for image upload handling (including SVG sanitization) on models to be quickly and easily configured.
Installation
You can install the package via composer:
composer require rpwebdevelopment/has-image-laravel
You can publish the config file with:
php artisan vendor:publish --tag="has-image-laravel-config"
The config file dictates the default storage disk to be used, while this can be overridden at a model level you may find it useful to configure to your default disk:
return [ 'default' => 'local', ];
Usage
namespace App\Models; use Illuminate\Database\Eloquent\Model; use RPWebDevelopment\HasImageLaravel\Dto\ImageDetails; use RPWebDevelopment\HasImageLaravel\Traits\HasImage; class Foo extends Model { use HasImage; protected $fillable = [ ... 'logo', ... ]; public function getImageDetails(): ImageDetails { /** * $storageDisk parameter is optional, if excluded the * default disk from your configuration will be accepted. * * $maintainFilename parameter is optional (false by default) * if true, the uploaded file will maintain the original filename * as uploaded. If false a hashed filename will be used. */ return ImageDetails::create( imageDirectory: 'DIR_NAME', imageFields: ['logo'], storageDisk: 'public', maintainFilename: true ); } }
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.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-18