anthonyedmonds/laravel-filestore 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Composer status Coverage status Laravel version NPM status PHP version Tests status

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:

  1. User uploads a file; this is added to the temp disk
  2. User removes an existing file; this is marked for removal
  3. 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

  1. Create a new FileStore class
    class MyFileStore extends FileStore
    {
        ...
    }
  2. Add the FileStore to your model
    class MyModel extends Model
    {
        ...
        protected $casts = [
            'file_column' => MyFileStore::class,
        ];
        ...
    }
  3. Tie your system into the FileStore ecosystem, such as through controllers
     class 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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固