Download the PHP package yassinedabbous/laravel-file-cast without Composer
On this page you can find all versions of the php package yassinedabbous/laravel-file-cast. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yassinedabbous/laravel-file-cast
More information about yassinedabbous/laravel-file-cast
Files in yassinedabbous/laravel-file-cast
Package laravel-file-cast
Short Description Easily link your uploads with their db columns
License MIT
Homepage https://github.com/YassineDabbous/laravel-file-cast
Informations about the package laravel-file-cast
Laravel File Cast
Easily link your uploads with their db columns
✨ Features
- Mapping uploaded files from the Request to the Model with ease.
- Old files are automatically cleaned on column update or model deleted.
- No extra code & No media table!
🔻 Installation
composer require yassinedabbous/laravel-file-cast
🧑💻 Usage
Just cast any of your table columns with FileCast::class like that:
This will cast the avatar column.
Assuming your request form has a file/image named avatar, you can assign the file to it's column:
Or fill the model:
It accept any type of file, so you can do that also:
What about deleting files ?
It has never been easier!
⚙️ Configuration
php artisan vendor:publish --tag=file-cast-config
You can set the default disk from the file-cast config file:
'disk' => 's3'
Or disable auto deleting:
'auto_delete' => FALSE
For Old Laravel Versions (< 11.x):
If you want to customize the disk for each column, you should modify your model with a public property/method that return an array containing the disk for each column: