PHPackages                             anthonyedmonds/laravel-filestore - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. anthonyedmonds/laravel-filestore

ActiveLibrary[File &amp; Storage](/categories/file-storage)

anthonyedmonds/laravel-filestore
================================

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

1.2.1(1mo ago)096↓75%1MITPHPPHP ^8.3

Since Jul 13Pushed 1mo agoCompare

[ Source](https://github.com/AnthonyEdmonds/laravel-filestore)[ Packagist](https://packagist.org/packages/anthonyedmonds/laravel-filestore)[ RSS](/packages/anthonyedmonds-laravel-filestore/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (4)Dependencies (8)Versions (5)Used By (1)

[![Composer status](.github/composer.svg)](.github/composer.svg)[![Coverage status](.github/coverage.svg)](.github/coverage.svg)[![Laravel version](.github/laravel.svg)](.github/laravel.svg)[![NPM status](.github/npm.svg)](.github/npm.svg)[![PHP version](.github/php.svg)](.github/php.svg)[![Tests status](.github/tests.svg)](.github/tests.svg)

Laravel FileStore
=================

[](#laravel-filestore)

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

What is this?
-------------

[](#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
------------

[](#installation)

You can install this library using Composer:

```
composer require anthonyedmonds/laravel-filestore
```

How to use
----------

[](#how-to-use)

1. Create a new `FileStore` class ```
    class MyFileStore extends FileStore
    {
        ...
    }
    ```
2. Add the `FileStore` to your model `$casts`, specifying the disks to use for storing files permanently and temporarily ```
    class MyModel extends Model
    {
        ...
        protected $casts = [
            'file_column' => MyFileStore::class . ':store,temp',
        ];
        ...
    }
    ```
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'),
            );
            ...
        }
    }
    ```

Restricting the FileStore
-------------------------

[](#restricting-the-filestore)

### AllowedInFileStore validation rule

[](#allowedinfilestore-validation-rule)

You can validate uploads destined for a `FileStore` using the `AllowedInFileStore` validation rule.

```
public function rules(): array
{
   return [
      'my-file' => [
         'required',
         new AllowedInFileStore($this->model->my_filestore),
         // OR, if not using maxStoreSize() or maxFiles()
         new AllowedInFileStore(MyFileStore::class),
      ],
   ];
}
```

It validates the following criteria:

- Is a file
- Is an allowed mime type
- Is below the file size limit

If provided with an instance of a `FileStore` from a `Model`, it will also check:

- Would not cause the `FileStore` to exceed its file count limit
- Would not cause the `FileStore` to exceed its store size limit

### Allowed mimes

[](#allowed-mimes)

You can set a list of allowed mime types using the `allowedMimes()` method in ".jpg" format.

This is used in combination with the `AllowedInFileStore` rule to restrict files being added to the store.

The `allowedMimesString()` method lets you get the list as a string for display, with or without dots.

### Maximum file size

[](#maximum-file-size)

You can set a maximum allowed upload file size in bytes using the `maxFileSize()` method.

This is used in combination with the `AllowedInFileStore` rule to restrict files being added to the store.

The `maxFileSizeString()` method can be used to display the limit.

### Maximum store size

[](#maximum-store-size)

You can set a maximum allowed `FileStore` size in bytes using the `maxStoreSize()` method.

This is used in combination with the `AllowedInFileStore` rule to restrict adding a file which would put the `FileStore` over the limit.

The `maxStoreSizeString()` and `currentStoreSizeString()` methods may be used to display the limit.

### Max files

[](#max-files)

You can set a maximum allowed number of files in the `FileStore` using the `maxFiles()` method.

This is used in combination with the `AllowedInFileStore` rule to restrict adding too many files to a `FileStore`.

The `maxFilesString()` and `countString()` methods can be used to display the limit.

### Permissions

[](#permissions)

You can set a permission name to be used for controlling access to the `FileStore` using the `permission()` method.

No access controls are included in this library, however it could be useful for dynamic calls to `authorise()`.

Roadmap
-------

[](#roadmap)

- Self-healing filestore
- Maximum overall filestore size

Help and support
----------------

[](#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
-------

[](#licence)

Published under the MIT licence.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance90

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

46d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17785811?v=4)[Anthony Edmonds](/maintainers/AnthonyEdmonds)[@AnthonyEdmonds](https://github.com/AnthonyEdmonds)

---

Top Contributors

[![AnthonyEdmonds](https://avatars.githubusercontent.com/u/17785811?v=4)](https://github.com/AnthonyEdmonds "AnthonyEdmonds (21 commits)")

---

Tags

laravelfilestoretempdraft

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/anthonyedmonds-laravel-filestore/health.svg)

```
[![Health](https://phpackages.com/badges/anthonyedmonds-laravel-filestore/health.svg)](https://phpackages.com/packages/anthonyedmonds-laravel-filestore)
```

###  Alternatives

[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.6M91](/packages/unisharp-laravel-filemanager)[laravel/ai

The official AI SDK for Laravel.

1.1k6.4M360](/packages/laravel-ai)[psalm/plugin-laravel

Psalm plugin for Laravel

3365.5M359](/packages/psalm-plugin-laravel)[erag/laravel-lang-sync-inertia

A powerful Laravel package for syncing and managing language translations across backend and Inertia.js (Vue/React/Svelte) frontends, offering effortless localization, auto-sync features, and smooth multi-language support for modern Laravel applications.

6036.2k](/packages/erag-laravel-lang-sync-inertia)[kolay/xlsx-stream

Streaming XLSX reader and writer for PHP and Laravel. Constant memory regardless of file size, direct S3 multipart streaming, optional born-indexed random access.

4616.8k](/packages/kolay-xlsx-stream)[ublabs/blade-simple-icons

A package to easily make use of Simple Icons in your Laravel Blade views.

1868.9k](/packages/ublabs-blade-simple-icons)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
