dillingham/interacts-with-uploads
Composer 安装命令:
composer require dillingham/interacts-with-uploads
包简介
Adds upload to request object
README 文档
README
Laravel trait adds FormRequest upload
Install
composer require dillingham/interacts-with-uploads
And add the following trait to your FormRequest classes
use \Dillingham\InteractsWithUploads;
Now you can call the following methods in controllers:
New uploads
$request->upload('key')
public function store(CreateProfileRequest $request) { $request->upload('banner'); $profile = Profile::create($request->validated()); return redirect()->route('profiles.show', $profile); }
Store the file and add it's path to validated() for the same key: banner
This makes $profile->banner equal to /uploads/asfos8asfoafaf9q3wf.jpg
Update uploads
$request->upload('binding.key')
public function update(UpdateProfileRequest $request, Profile $profile) { $request->upload('profile.banner'); $profile->update($request->validated()); return redirect()->route('profiles.show', $profile); }
If the request has a new file for key, it deletes the old and uploads the new
If no new file is in the request, it will add the original file path back to validated()
So submitting null for that key will result in the same path / no changes to the model.
It will get the original file path using the key & route model binding, in this scenario.. profile
The binding profile connects a typehinted model & defined in Route:: using {binding} syntax
Manual update
If you are not using route model binding, you can manually set the path to update.
public function update(UpdateProfileRequest $request, Profile $profile) { $request->updateUpload($profile, 'banner'); $profile->update($request->validated()); return redirect()->route('profiles.show', $profile); }
Parameters
You can specify a few options and override the defaults.
$request->upload('banner', 'uploads', 'public');
uploads: is the default path within storagepublic: is the default disk within config/filesystems
Author
dillingham/interacts-with-uploads 适用场景与选型建议
dillingham/interacts-with-uploads 是一款 基于 HTML 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dillingham/interacts-with-uploads 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dillingham/interacts-with-uploads 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-04