nour / images
使用不同实体管理图片
1.0.0.3
2019-07-13 21:47 UTC
Requires
- intervention/image: 2.4
This package is auto-updated.
Last update: 2024-09-14 10:53:56 UTC
README
使用不同实体管理图片
要求
- PHP >=5.4
- Fileinfo 扩展
支持的图像库
- GD 库 (>=2.0)
- Imagick PHP 扩展 (>=6.5.7)
安装
composer require nour/images
安装 Intervention Image 后,打开您的 Laravel 配置文件 config/app.php 并添加以下行。
在 $providers 数组中添加此包的服务提供者。
Nour\Images\Providers\ImagesServiceProvider::class,
将 Imageable 添加到您想要使用图片管理器的每个模型中。
- 例如:
use Notifiable,Imageable;
php artisan migrate
代码示例
// get user $user=Auth::user(); // upload photo $user->photo($request->file('photo'))->upload(); // resize image instance $user->photo($request->file('photo'))->width(756)->height(425)->upload(); //get image src $user->getImage() // get image model $user->Image;
存储
在每个模型中添加: protected $photoPath="{path}"; 例如: protected $photoPath="user";
所有图片存储在
public\images\$photoPath- 请创建正确的文件夹路径