Download the PHP package abdelrahmanbl/laravel-uploadable without Composer
On this page you can find all versions of the php package abdelrahmanbl/laravel-uploadable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abdelrahmanbl/laravel-uploadable
More information about abdelrahmanbl/laravel-uploadable
Files in abdelrahmanbl/laravel-uploadable
Package laravel-uploadable
Short Description this package adding behaviour to a model for self uploading images like avatar or any files type.
License
Informations about the package laravel-uploadable
laravel-uploadable
Laravel Uploadable for adding behaviour to a model for self uploading file like avatar or any file type.
Introduction
This package can help you to upload image or any type of file to a specific destination in your filesystem, you can determine a path for a directory to save your uploaded file for each field in your table with minimal configurations or you can use the default store directory of the package.
Installation
About Upload
This package uses the Laravel File Storage to keep the file management. The file will be stored inside the default disk. For example, if you are using the public disk, to access the image or file, you need to create a symbolic link inside your project:
And then, configure your default filesystem from .env file
You can add default_url
to the filesystems config file to overwrite the default file url.
The default file url is asset('uploadable.jpg').
Usage
To use this package, import the FileCast in your model And then configure the $casts of your model with the FileCast class.
Customize The Directory
Customize The Disk
Customize The Driver
Note: your customer driver service must implement
Bl\LaravelUploadable\Interfaces\UploadFileInterface
and has a constructor with parameter $disk
Customize The Default Path
That's all! After this configuration, you can send file data from the client side with the same name of each file field of the model. The package will make the magic!
Example
In frontend you can create a form-data with field name avatar.
In backend you can pass all the data to the User model.
You can update the file manually to the User model.
Note: when update a field with a file the package will automatic delete the old file and put the new one.
Delete The File
You can use the FileCastRemover trait in your model and when you deleting the model instance all the related files will be deleted automatically.
And once the model instance is deleted all it's related files will be removed.
Apply The Events
You can apply events either before or after the file upload. In addition to, you can apply that globally or for custom field.
Global Events
- For apply global events before the file upload you should define a method called
beforeFileCastUpload
in your model and it take one paramter with type\Illuminate\Http\UploadedFile
and return the same type. - For apply global events after the file uploaded you should define a void method called
afterFileCastUpload
in your model and it take one paramter with type\Illuminate\Http\UploadedFile
.
Custom Events
For apply custom events you should create a service that implement Bl\LaravelUploadable\Interfaces\EventUploadInterface
and path it as a parameter.
Note: when applying global and custom events in your model the priority go to the custom event.
Contributing
Feel free to comment, open issues and send PR's. Enjoy it!!
License
The MIT License (MIT). Please see License File for more information.