blocksystems/file-attributes

通过文件对laravel(lumen)的服务模型属性进行打包

dev-main 2021-10-19 17:58 UTC

This package is not auto-updated.

Last update: 2024-10-02 08:11:00 UTC


README

Version License

文档

laravel(lumen)的文件属性

此Composer自动上传文件并在删除之前删除文件

[在你的模型类中]

protect $fileable = ['thumbnail', 'profile'];

例如(当模型创建时)

User::create(['thumbnail' => $request->file('thumbnail'), 'profile' => $request->file('profile')]);
$user->thumbnail; // will be 's3 or local path'

例如(多个文件 ※但如果你想这样,请将属性转换为JSON,例如 "php protected $casts = ['attribute' => 'json']')

User::create(['thumbnail' => [$request->file('thumbnail'), $request->file('profile')]]);

##设置前缀文件路径

protect $filablePrefix = 'admin'; // including slash or not, everything is OK.

##设置文件路径

protect $filablePath = 'admin/files'; // including slash or not, everything is OK.

##设置关闭在属性更改或删除时自动删除文件

protect $fileAutoDeleting = false;  // default : true

##每次属性值更改时,将动态更改文件到URL字符串

protect $fileableSync = true; // default : false

例如

$user->thumbnail = $request->file('thumbnail');
// (without saving) will be 's3 or local path'