Download the PHP package / without Composer
On this page you can find all versions of the php package /. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Rated 5.00 based on 2 reviews
Informations about the package
Laravel Fileable
Laravel Fileable exposes methods that make handling file upload with Laravel filesystem even easier, it also exposes a trait that automatically handles file uploads for you with support for uploading base64 encoded files.
Installation
You can install the package via composer:
Installation
Laravel automatically discovers and publishes service providers but optionally after you have installed Laravel Fileable, open your Laravel config file config/app.php and add the following lines.
In the $providers array add the service providers for this package.
Add the facade of this package to the $aliases array.
Configuration
By default Laravel Fileable avatar
and media
directories and symlinks to your storage/app/public
directories, and also adds the file
directory to your storage/app
directory.
You may change this or decide to modify the directories that will be created by running the following artisan command.
The configuration file is copied to config/toneflix-fileable.php. With this copy you can alter the settings for your application locally.
Generating symlinks
After publishing and modifying the configuration, both of which are optional you will need to run the following artisan command to actually generate the required symlinks by running the following artisan command.
Collections
The collection
config option define where files should be stored and optionally a default file that should be returned when the requested file is not found.
Image Sizes
This package uses Intervention Imagecache to generate responsive images for image files on demand, the image_sizes
config option defines which responsive sizes to generate, you are not limited to use the defined sizes, take a look at Intervention Imagecache Documentation for information about customizsing this feature.
File Route Secure
The file_route_secure
config option sets the route from which secure images should be loaded from. The route accepts one parameter, the {file}
parameter.
File Route Open
The file_route_open
config option sets the route from which secure images which do not require authentication or authorization should be loaded from. The route accepts one parameter, the {file}
parameter.
Secure File Middleware
The file_route_secure_middleware
config option sets which middleware to apply when using the protected files collection.
Symlinks
The symlinks
option maps where Intervention Imagecache should search for images in your app, this does not overide your current Intervention Imagecache configuration, it appends.
Image Templates
The image_templates
option generates image filters based on Intervention Imagecache templates, this also does not overide your current Intervention Imagecache configuration, it appends.
Usage
To automatically discover files in request and save them to storage and database you will need to add the ToneflixCode\LaravelFileable\Traits\Fileable
trait to your models and register the required filables using the fileableLoader()
method from the ToneflixCode\LaravelFileable\Traits\Fileable
trait.
The fileableLoader()
method accepts and array of [key => value]
pairs that determines which files should be auto discovered in your request, the key
should match the name field in your input field E.g <input type="file" name="avatar">
, the value
should be an existing collection in your Laravel Fileable configuration.
OR
The fileableLoader()
method also accepts the key
as a string as the first parameter and the value
as a string as the second parameter.
Loading|Not Loading default media.
The third parameter of the fileableLoader()
is a boolean value that determines wether to return null or the default image when the requested file is not found.
Supporting old setup (Legacy Mode)
If you had your model running before the introducation of the the Fileable trait, you might still be able to load your existing files by passing a fourth parameter to the fileableLoader()
, the Legacy mode attempts to load media files that had been stored or managed by a different logic before the introduction of the fileable trait.
Model Events
If you use listen to laravel events via the boot()
you would need to move your event handles to the registerEvents()
method of the ToneflixCode\LaravelFileable\Traits\Fileable
trait.
This should be defined in your model to overide the default handles.
Model Attributes
Laravel Fileable exposes 3 model Attributes which will help with accessing your saved files
defaultImage()
This attribute exposes the default image of the ToneflixCode\LaravelFileable\Traits\Fileable
trait
Depending on the collections you have created, you may need to add the default image file to the respective directories within the collections.
mediaFile()
Returns a single media link from list of all bound files (Usefull especially when you are binding only a single resource)
mediaFileInfo()
Returns the attribute of a single media file (Usefull especially when you are binding only a single resource)
getFiles()
Returns a list of bound files with a little more details like mime, isImage, url, path and size
files()
This attribute exposes all images registered with the fileableLoader()
method of the ToneflixCode\LaravelFileable\Traits\Fileable
trait
responsiveImages()
If the registered files are images this attribute exposes responsive images for them or returns the defual image
Prefixed Media Collections
While the library will try to resolve media files from the configured collection, you can also force media file search from collections different from the configured ones by saving the path reference on the database with a collection:filename.ext
prefix, this will allow the system to look for media files in a collection named collection
even if the current collection for the model is a collection named images
;
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Toneflix Code
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of with dependencies
illuminate/filesystem Version ^8.1|^9.0|^10.0|^11.0
illuminate/support Version ^8.1|^9.0|^10.0|^11.0
intervention/image Version ^3.5