Has-Files is a package that provides a quick and easy way to link files with a model for Laravel.
This package depends on Uploader.
Install the latest version using Composer.
1composer require pharaonic/laravel-has-files
2php artisan migrate
Files uploading is gonna be easiest thing you will think about, so you will be able to store, retrieve, update and delete files so easily.
You have to include HasFiles trait into your model first.
Optional : You can customize the uploading options through Uploader.
6class Person extends Model
8 use HasFiles;
10 protected $filesAttributes = ['passport'];
12 protected $filesOptions = [ ...
13 'passport' => [
14 'directory' => '/papers/passports',
15 'thumbnail' => [
16 'ratio' => true,
17 'width' => 350,
18 'height' => null
This is how you can store files into your model, you can do that on create or replace the file with a new one.
1// On Create
2$person = Person::create([
3 'passport' => $request->passport
6// Replace File
7$person->passport = $request->passport;
You can retrieve the file easily or it's thumbnail too.
You can delete a single file or all files or the model with the files too.
1// Delete Single File
4// Delete All Files
7// Delete Model With It's Files too
You can publish the migrations.
1php artisan vendor:publish --tag=laravel-has-files