PHPackages                             mohammedmanssour/file-cast - 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. mohammedmanssour/file-cast

ActiveLibrary

mohammedmanssour/file-cast
==========================

Easily manage uploaded files in your Laravel app, with automatic path saving and handy value objects for effortless access.

v0.4.0(1y ago)6317↓100%MITPHPPHP ^8.2CI failing

Since May 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mohammedmanssour/file-cast)[ Packagist](https://packagist.org/packages/mohammedmanssour/file-cast)[ Docs](https://github.com/mohammedmanssour/file-cast)[ GitHub Sponsors]()[ RSS](/packages/mohammedmanssour-file-cast/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (8)Versions (6)Used By (0)

File Cast
=========

[](#file-cast)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8056525839561fd51346937733687598033ff90ec0a4862fde65ea737fa18cc4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f68616d6d65646d616e73736f75722f66696c652d636173742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mohammedmanssour/file-cast)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/2f23a729d247cd92ddf1b8aa9ae9e325568cbb3bbb93ba9027d0b66003484ccc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f68616d6d65646d616e73736f75722f66696c652d636173742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/mohammedmanssour/file-cast/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/75b9b148c63b85ff4bf8f0be4b7afdc78990ad8e4b828b324589f2da4af4e7d7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f68616d6d65646d616e73736f75722f66696c652d636173742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mohammedmanssour/file-cast)

This Laravel package makes file management straightforward. It automatically saves uploaded files to the disk and stores their paths in the database. When you retrieve these files, it wraps the paths in easy-to-use value objects. The package also keeps track of any changes, ensuring old files are deleted when updates occur. It’s a simple way to keep your file handling neat and efficient.

Features
--------

[](#features)

- Mapping uploaded files from the Request to the Model.
- Old files are automatically deleted upon model update or deletion.
- File Value Object for easy access

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

[](#installation)

You can install the package via composer:

```
composer require mohammedmanssour/file-cast
```

You can publish the config file with:

```
php artisan vendor:publish --tag="file-cast-config"
```

Usage
-----

[](#usage)

1. Add the `FileCast` to your casts list

```
protected $casts = [
    'government_id' => FileCast::class, // uses table name as storage path, public visibility and the configured default disk
    'verification_video' => FileCast::class.':verification', // uses verification as storage path, public visisbility and the configured default disk
    'profile_picture' => FileCast::class.':pics,,s3', // uses pics as storage path, and s3 as storage disk
];
```

2. **Optional**, if you want to clean old files upon model update or delete, add the following observer to your model

```
User::observe(UploadedFilesObserver::class);
```

3. On Model Retrieval, the casted attribute is converted to a file object that provides the following method

```
$model->profile_picture->path(); // return the saved path in the db.
$model->profile_picture->fullPath(); // return the full path based on the provided disk
$model->profile_picture->size(); // return the file size
$model->profile_picture->url(); // return the file url based on the provided disk
$model->profile_picture->exists(); // return true of false
$model->profile_picture->delete(); // delete the file
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Mohammed Manssour](https://github.com/mohammedmanssour)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance45

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

Total

5

Last Release

425d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/aeb75f35979097845cce704062910a6a8c85bc0a7b49b081df7350a4f20023fc?d=identicon)[manssour.mohammed](/maintainers/manssour.mohammed)

---

Top Contributors

[![mohammedmanssour](https://avatars.githubusercontent.com/u/19733629?v=4)](https://github.com/mohammedmanssour "mohammedmanssour (9 commits)")

---

Tags

laravelfile castMohammed Manssour

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/mohammedmanssour-file-cast/health.svg)

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

###  Alternatives

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[mozex/laravel-scout-bulk-actions

A Laravel Scout extension for bulk importing and flushing of all models.

1033.4k](/packages/mozex-laravel-scout-bulk-actions)

PHPackages © 2026

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