mvaliolahi/attachable

此包允许您将文件附加到Eloquent模型。

1.0.4 2022-11-09 12:44 UTC

This package is auto-updated.

Last update: 2024-09-09 17:07:47 UTC


README

安装

$ composer require mvaliolahi/attachable
class Post extends Model
{
    use Attachable;

    protected $attachable = [
        'image',
        'cover'
    ];

    public function coverUrl()
    {
        return asset(Storage::url($this->cover));
    }

更改上传路径

默认情况下,文件将上传到public目录,但您可以通过在模型中添加$upload_path属性来更改它。

protected $upload_path = 'public';

为每个用户分离文件

此属性是可选的,允许每个用户的文件保存到单独的文件夹。

protected $user_directory = true;

调整图片大小

此属性是可选的。

protected $resize_image = [
    'avatar' => [
        'fit' => true, // default is false and will resize the image to the given size
        'width' => 200,
        'height' => 200,
        'quality' => 90 # this is optional, default is 100
        'resize_if_width' => 1024, // resize if width is greater than 1024
    ]
];