PHPackages                             vhar/laravel-files - 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. vhar/laravel-files

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

vhar/laravel-files
==================

Associate files with Eloquent models

1.0.1(1mo ago)02MITPHP ^8.2

Since Jul 6Compare

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

READMEChangelog (1)Dependencies (6)Versions (3)Used By (0)

Laravel Files
=============

[](#laravel-files)

A lightweight Laravel package for uploading files and attaching them to Eloquent models.

Features
--------

[](#features)

- Upload files to any Laravel filesystem disk
- Associate files with any Eloquent model
- Organize files into collections
- Automatic orphan file cleanup
- Optional file deduplication using checksum
- Laravel 11 &amp; 12 support
- PHP 8.2+

---

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

[](#installation)

Install the package via Composer:

```
composer require vhar/laravel-files
```

Publish &amp; Run migrations:

```
php artisan vendor:publish --tag=laravel-files-migrations
php artisan migrate
```

Optionally publish the configuration:

```
php artisan vendor:publish --tag=laravel-files-config
```

If you want to customize the database structure, publish the migration stubs:

```
php artisan vendor:publish --tag=laravel-files-migrations
```

---

Configuration
-------------

[](#configuration)

```
return [

    /*
     * Default filesystem disk.
     */
    'disk' => env('FILES_DISK', 'public'),

    /*
     * Reuse existing file records when checksum matches.
     */
    'deduplicate' => true,

    /*
     * Automatically delete files that are no longer attached.
     */
    'delete_orphan_files' => true,

    /*
     * Hash algorithm with used for deduplicates
    */
    'hash_algo' => 'sha1',
];
```

---

Usage
-----

[](#usage)

### Upload a file

[](#upload-a-file)

```
use Vhar\LaravelFiles\Facades\LaravelFiles;

$file = LaravelFiles::upload($request->file('image'));
```

Or specify directory and disk:

```
$file = LaravelFiles::upload(
    $request->file('image'),
    'quiz/images',
    'public'
);
```

---

### Attach a file

[](#attach-a-file)

```
LaravelFiles::attach($news, $file);
```

Attach to a collection:

```
LaravelFiles::attach($news, $file, 'gallery');
```

---

### Detach a file

[](#detach-a-file)

Detach from all collections:

```
LaravelFiles::detach($news, $file);
```

Detach only from one collection:

```
LaravelFiles::detach($news, $file, 'gallery');
```

---

### Force delete

[](#force-delete)

Remove the file from every model and delete it from storage.

```
LaravelFiles::forceDelete($file);
```

---

### Check file exists

[](#check-file-exists)

```
LaravelFiles::exists($file);
```

---

HasFiles trait
--------------

[](#hasfiles-trait)

Add the trait to any Eloquent model.

```
use Vhar\LaravelFiles\Traits\HasFiles;

class Quiz extends Model
{
    use HasFiles;
}
```

Access files:

```
// Get the first file
$news->file();

// Get the first file from a specific collection
$news->file('gallery');

// Get all files
$news->files()->get();

// Get files from a specific collection
$news->files('gallery')->get();
```

Attach via trait:

```
$news->addFile($file, 'gallery');
```

Remove:

```
$news->removeFile($file, 'gallery');
```

---

File model
----------

[](#file-model)

```
$file->url();

$file->humanSize();

$file->size;

$file->mime_type;

$file->original_name;
```

---

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance92

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

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

Total

2

Last Release

40d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5484416?v=4)[Vladimir Kharinenkov](/maintainers/vhar)[@vhar](https://github.com/vhar)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vhar-laravel-files/health.svg)

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

###  Alternatives

[illuminate/filesystem

The Illuminate Filesystem package.

16166.4M3.5k](/packages/illuminate-filesystem)

PHPackages © 2026

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