anthonyedmonds/laravel-filestore

Manage adding and removing files on your Model, only persisting the changes on save!

Maintainers

Package info

github.com/AnthonyEdmonds/laravel-filestore

pkg:composer/anthonyedmonds/laravel-filestore

Transparency log

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 1

1.0.0 2026-07-13 12:19 UTC

This package is auto-updated.

Last update: 2026-07-14 13:26:47 UTC


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.