PHPackages                             anourvalar/eloquent-file - 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. [Database &amp; ORM](/categories/database)
4. /
5. anourvalar/eloquent-file

ActiveLibrary[Database &amp; ORM](/categories/database)

anourvalar/eloquent-file
========================

Database (Eloquent) layer for files management

1.43.13(1mo ago)04.1k↓13.3%MITPHPPHP ^8.3CI failing

Since May 16Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/AnourValar/eloquent-file)[ Packagist](https://packagist.org/packages/anourvalar/eloquent-file)[ Docs](https://github.com/AnourValar/eloquent-file)[ RSS](/packages/anourvalar-eloquent-file/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (136)Used By (0)

Laravel Eloquent File
=====================

[](#laravel-eloquent-file)

Installation
------------

[](#installation)

```
composer require anourvalar/eloquent-file
```

```
php artisan vendor:publish --tag=AnourValar\EloquentFile\Providers\EloquentFileServiceProvider
```

Prune command
-------------

[](#prune-command)

```
$schedule->command('eloquent-file:on-zero --days=10')->dailyAt('00:30')->runInBackground()->onOneServer();
```

Relation
--------

[](#relation)

```
/**
 * @return \Illuminate\Database\Eloquent\Relations\MorphMany
 */
public function fileVirtuals(): \Illuminate\Database\Eloquent\Relations\MorphMany
{
	return $this->morphMany(\App\FileVirtual::class, 'entity', 'entity')->orderBy('id', 'ASC');
}
```

Observer
--------

[](#observer)

```
public function deleting(Model $model)
{
	// FileVirtuals
	foreach ($model->fileVirtuals()->get() as $item) {
		$item->delete();
	}
}
```

Proxy download
--------------

[](#proxy-download)

```
// Url signed (web_file group with file prefix)
Route::controller(App\Http\Controllers\FileController::class)->group(function () {
    Route::any('/{file_virtual}/download/{filename}', 'download')
        ->middleware('throttle:lax')->name('file.download');
    // $this->proxyUrlSigned($request);
});

// User authorized (web_file group with file prefix)
Route::controller(App\Http\Controllers\FileController::class)->group(function () {
    Route::any('/{file_virtual}/download/{filename}', 'download')
        ->middleware('auth:sanctum', 'throttle:lax')->name('file.download');
    // $this->proxyUserAuthorize($request);
});
```

Route
-----

[](#route)

```
\Route::pattern('file_virtual', '[0-9]{1,18}'); // RouteServiceProvider
\Route::pattern('entity_id', '[0-9]{1,18}'); // RouteServiceProvider

Route::prefix('/file')
    ->controller(App\Http\Controllers\Api\FileController::class)
    ->group(function () {
        Route::post('/upload/{entity}/{entity_id}/{name}', 'upload'); // + middleware
        Route::post('/delete/{file_virtual}', 'delete'); // + middleware
    });
```

Controller
----------

[](#controller)

```
class FileController extends Controller
{
    use \AnourValar\EloquentFile\Traits\ControllerTrait;

    /**
     * Web-service: Upload a file
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function upload(Request $request): array
    {
        $fileVirtual = \DB::transaction(function () use ($request) {
            return $this->uploadFileFrom($request);
        });

        return ['file_virtual' => ['id' => $fileVirtual->id]];
    }

    /**
     * Web-service: Delete a file
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function delete(Request $request)
    {
        \DB::transaction(function () use ($request) {
            $this->deleteFileFrom($request);
        });

        return ['file_virtual' => ['id' => (int) $request->route('file_virtual')]];
    }
}
```

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance91

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 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 ~16 days

Recently: every ~2 days

Total

135

Last Release

45d ago

PHP version history (4 changes)1.0.0PHP &gt;=7.1.0

1.12.0PHP &gt;=8.0

1.20.0PHP ^8.0

1.38.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/db1765d50b04dca380c835746bee50f75be1683fd930f276def046cef17f5d2c?d=identicon)[AnourValar](/maintainers/AnourValar)

---

Top Contributors

[![AnourValar](https://avatars.githubusercontent.com/u/54237693?v=4)](https://github.com/AnourValar "AnourValar (153 commits)")

---

Tags

laraveleloquentfileanourvalarupload

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/anourvalar-eloquent-file/health.svg)

```
[![Health](https://phpackages.com/badges/anourvalar-eloquent-file/health.svg)](https://phpackages.com/packages/anourvalar-eloquent-file)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[mostafaznv/larupload

Larupload is a ORM based file uploader for laravel to upload image, video, audio and other known files.

73403.7k3](/packages/mostafaznv-larupload)[qcod/laravel-imageup

Auto Image upload, resize and crop for Laravel eloquent model using Intervention image

775113.8k](/packages/qcod-laravel-imageup)[bavix/laravel-clickhouse

Eloquent model for ClickHouse

72214.1k2](/packages/bavix-laravel-clickhouse)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)[visual-ideas/moonshine-spatie-medialibrary

Spatie\\MediaLibrary field for MoonShine Laravel admin panel

2014.1k](/packages/visual-ideas-moonshine-spatie-medialibrary)

PHPackages © 2026

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