sehrgut/laravel-attachments

此包已被弃用,不再维护。未建议替代包。

特性:使将文件附加到Eloquent模型变得超级简单!

dev-master 2018-06-14 15:06 UTC

This package is not auto-updated.

Last update: 2023-03-04 21:33:36 UTC


README

创建附件数据库列

为模型中的每个附件创建一个数据库字段(可空字符串),例如:

$table->string('profile_image')->nullable();

按如下方式在模型中定义附件

protected $image_attachments = [
	'profile_image' => [
	    'path' => 'uploads/user/avatar',
	    'defaults' => [
	        'small' => '.jpg',
	        'medium' => '.jpg',
	        'large' => '.jpg',
	    ],
	    'styles' => [
	        'small' => '100',
	        'medium' => '500',
	        'large' => '1000'
	    ]
	],
	'background_image' => [
	    'path' => 'uploads/user/background',
	    'defaults' => [
	        'small' => '.jpg',
	        'medium' => '.jpg',
	        'large' => '.jpg',
	    ],
	    'styles' => [
	        'small' => '100',
	        'medium' => '500',
	        'large' => '1000'
	    ]
	]
];

使用方法

非常简单,就像这样:

$me->updateImageAttachment('profile_image', $request->fileContent(), $request->fileType());