anthonyedmonds/laravel-filestore
Composer 安装命令:
composer require anthonyedmonds/laravel-filestore
包简介
Manage adding and removing files on your Model, only persisting the changes on save!
README 文档
README
Laravel FileStore
Manage adding and removing files on your Model, only persisting the changes on save!
What is this?
Forms with files which allow the user to draft changes before committing to them, need a way to manage the uploading and removal of files only once the user commits to them.
This library adds a FileStore cast which automatically handles these changes:
- User uploads a file; this is added to the temp disk
- User removes an existing file; this is marked for removal
- User saves the
Model; this moves temp files to store, and removes marked files from store
The underlying FileStore object is saved as a JSON string, which can be stored in a text column.
The FileStore class provides all the methods you need to add, remove, and list your files.
Your Model can have one FileStore per attribute for complete compartmentalisation.
Files are stored as $hash on the temporary disk, and $model->id/$hash on the store disk.
Installation
You can install this library using Composer:
composer require anthonyedmonds/laravel-filestore
How to use
- Create a new
FileStoreclassclass MyFileStore extends FileStore { ... }
- Add the
FileStoreto your modelclass MyModel extends Model { ... protected $casts = [ 'file_column' => MyFileStore::class, ]; ... }
- Tie your system into the
FileStoreecosystem, such as through controllersclass MyController extends Controller { public function download(MyModel $model, string $hash): StreamedResponse { return $model->file_column->download($hash); } public function index(MyModel $model): View { return view('my-view', [ 'files' => $model->file_column->list(), ]); } public function remove(MyModel $model, string $hash): RedirectResponse { $model->file_column->remove($hash); ... } public function save(MyModel $model): RedirectResponse { // Added and removed files will be processed when you call `save()` on the Model $model->save(); ... } public function upload(FileRequest $formRequest, MyModel $model): RedirectResponse { $model->file_column->add( $formRequest->file('uploaded_file'), ); ... } }
Roadmap
- Self-healing filestore
Help and support
You are welcome to raise any issues or questions on GitHub.
If you wish to contribute to this library, raise an issue before submitting a forked pull request.
Licence
Published under the MIT licence.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-13