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 table columns
Table of Content
- :sparkles: Features
- :small_red_triangle_down: Installation
- :technologist: Usage
- :card_file_box: Supported data formats
- Uploaded file
- Local file path
- Remote file url
- Base64 URI
- Json string
- Arrays (Json & CSV)
- NULL ?
- :hammer_and_wrench: Functionalities
- Storage Proxy
- Additional Methods
- File Manipulation (Move & Delete)
- Extending
- :card_file_box: Supported data formats
- :gear: Configuration
:sparkles: Features
- Mapping uploaded files from the Request to the Model with ease.
- Dealing with multiple forms of data (File instance, Local path, Remote url, Base64 URI, Array values ...).
- Old files are automatically cleaned on update and delete events.
- No extra code & No media table!
:small_red_triangle_down: Installation
composer require yassinedabbous/laravel-file-cast
:technologist: Usage
Just cast any of your table columns with FileCast::class like that:
This will cast the avatar column.
For Old Laravel Versions (< 11.x):
If for any reason you want to customize the disk with a dynamic value, you should modify your model with a public method that returns an array containing the disk name for each column:
:card_file_box: Supported data formats
• Uploaded file:
Assuming your request form has a file/image named "avatar", you can assign the file to it's column:
Or even fill the model with request input:
It accept any type of file, so you can do that also:
• Local file path:
• Remote file url:
• Base64 URI:
• JSON string:
• Array as JSON or CSV:
• NULL ?
Null value will cause automatic file deletion (configurable):
It has never been easier!
:hammer_and_wrench: Functionalities:
To provide more functionalities to file caster, this package uses a wrapper class name FileField, this class works as a proxy to the Storage facade with some additional methods.
• Storage Proxy
As a proxy to the Laravel Storage facade, you can call any method from Storage directly on the file field without providing the file path:
• Additional Methods
In addition to Storage methods, FileField comes with some useful methods:
• File Manipulation
- Deleting file:
Old files are cleaned automatically when column value updated.
To automatically delete old files on Model deleted event, add HasFileCast trait to your model.
To delete files manually:
- Moving file to new path:
• Extending
File Cast is "macroable", which allows you to add additional methods to FileField class at run time. The FileField class' macro method accepts a closure that will be executed when your macro is called. The macro closure may access the FileField's other methods via $this, just as if it were a real method of the FileField class. For example, the following code adds a resize method to the FileField class:
:gear: Configuration
You can optionally publish the config file with:
php artisan vendor:publish --tag=file-cast-config
These are the contents of the default config file that will be published: