blocksystems / file-attributes
通过文件对laravel(lumen)的服务模型属性进行打包
dev-main
2021-10-19 17:58 UTC
Requires
- php: >=7.1.3
- illuminate/support: 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0 || ^7.0 || ^8.0
- league/flysystem: ^1.1
- league/flysystem-aws-s3-v3: ~1.0
Requires (Dev)
- illuminate/database: ^6.20.12 || ^7.30.4 || ^8.24.0
This package is not auto-updated.
Last update: 2024-10-02 08:11:00 UTC
README
文档
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'