PHPackages                             sabbir268/laravel-filecaster - 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. sabbir268/laravel-filecaster

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

sabbir268/laravel-filecaster
============================

A simple casting class for laravel model to handle file upload and retrieve

v2.0.1(1y ago)152601MITPHPPHP ^7.4|^8.0

Since Aug 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/sabbir268/laravel-filecaster)[ Packagist](https://packagist.org/packages/sabbir268/laravel-filecaster)[ Docs](https://github.com/sabbir268/laravel-filecaster)[ RSS](/packages/sabbir268-laravel-filecaster/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (16)Used By (0)

laravel-filecaster
==================

[](#laravel-filecaster)

A simple file casting for laravel model to handle file upload and retrieve

---

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

[](#installation)

```
composer require sabbir268/laravel-filecaster
```

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

[](#configuration)

**Cast Class Alias**Add in aliases array (optional)

```
'aliases' => Facade::defaultAliases()->merge([
    // ...
    'filecast' => Sabbir268\LaravelFileCaster\FileCaster::class,
    // ...
])->toArray(),
```

Publish config file

```
php artisan vendor:publish --provider="Sabbir268\LaravelFileCaster\FileCasterServiceProvider"
```

Use from Model
--------------

[](#use-from-model)

#### Import FileCaster class

[](#import-filecaster-class)

```
use Sabbir268\LaravelFileCaster\FileCaster;
```

### Example: manage "image" file upload and retrieve

[](#example-manage-image-file-upload-and-retrieve)

Let's assume, we have Blog model and there is a column `image` to store image file.

```
use App\Models;
use Sabbir268\LaravelFileCaster\FileCaster;

class Blog extends Model
{
    // ...
    protected $casts = [
        'image' => FileCaster::class,
    ];
    // ...
}
```

Or, you can use `filecast` as alias of `Sabbir268\LaravelFileCaster\FileCaster` class.

```
use App\Models;

class Blog extends Model
{
    // ...
    protected $casts = [
        'image' => 'filecast',
    ];
    // ...
}
```

Now when you will create a new Blog model instance and has a file from request assign to `image` property, it will automatically upload the file to `storage/app/public/{class_name}/{id}` directory and store the file name with path in `image` column.

```
$blog = new Blog();
$blog->image = $request->file('image');
$blog->save();
```

And when you will retrieve the model instance, it will automatically retrieve the file path from `image` column and you can use it as like as a string.

```
$blog = Blog::find(1);
echo $blog->image; // output: /storage/blog/1/image.jpg
```

#### There several methods/property you can use to retrieve the file information.

[](#there-several-methodsproperty-you-can-use-to-retrieve-the-file-information)

```
// get file name
$blog->image->name; // output: image.jpg

// get file extension
$blog->image->extension; // output: jpg

// get file size
$blog->image->size; // output: 1024

// get image width
$blog->image->width; // output: 200

// get image height

$blog->image->height; // output: 200

// get file mime type
$blog->image->mime; // output: image/jpeg

// get file http url
$blog->image->url; // output: http://example.com/storage/blog/1/image.jpg

// get file full path
$blog->image->path; // output: /var/www/html/storage/app/public/blog/1/image.jpg

// get storage directory
$blog->image->dir; // output: /var/www/html/storage/app/public/blog/1

// check if file exists
$blog->image->exists; // output: true
```

If you want to get manipulated image url, you can use `ur('WIDTHxHEIGHT')` method.

```
$blog->image->url('200x200'); // output: http://example.com/storage/cache/200x200/blog-2-image1.jpg
```

Note: It will create a manipulated image in storage cache directory. You will need `gd` or `imagick` extension installed in your server.

If you want to delete the file, you can use `remove()` method.

```
$blog->image->remove(); // output: true
```

Contribution
------------

[](#contribution)

You're open to create any pull request.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance40

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

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

Recently: every ~9 days

Total

15

Last Release

513d ago

Major Versions

v0.5.0 → v1.0.02023-08-19

v1.2.0 → v2.0.02024-12-15

PHP version history (3 changes)v0.1.0PHP ^7.4

v0.2.0PHP &gt;=7.4

v0.3.0PHP ^7.4|^8.0

### Community

Maintainers

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

---

Top Contributors

[![sabbir268](https://avatars.githubusercontent.com/u/34827803?v=4)](https://github.com/sabbir268 "sabbir268 (22 commits)")

---

Tags

filefile-uploadfile-castingfile-retrievefile-upload-laravelfile-casting-laravelfile-retrieve-laravellaravel-file-uploadlaravel-casting

### Embed Badge

![Health badge](/badges/sabbir268-laravel-filecaster/health.svg)

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

###  Alternatives

[unisharp/laravel-filemanager

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

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[itskodinger/midia

Simple Media manager for your Laravel project

1415.8k](/packages/itskodinger-midia)[jasekz/laradrop

File manager using Dropzone.js for Laravel 5 | 6 | 7 | 8

7310.3k1](/packages/jasekz-laradrop)[kingofcode/laravel-uploadable

Laravel Uploadable trait to automatically upload images and files with minimum configuration

286.4k](/packages/kingofcode-laravel-uploadable)[xefi/faker-php-images

Faker extension to generate images

402.6k](/packages/xefi-faker-php-images)

PHPackages © 2026

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