Download the PHP package toneflix-code/laravel-fileable without Composer

On this page you can find all versions of the php package toneflix-code/laravel-fileable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-fileable

Laravel Fileable

Test & Lint Latest Stable Version Total Downloads License PHP Version Require codecov

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:

Package Discovery

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.

Upgrading

Version 2.x is not compatible with version 1.x, if you are ugrading from version 1.x here are a few notes:

Config

  1. If you published the configuration file, remove image_templates. Templates are no longer needed, just set you responsive image sizes using the image_sizes property.

  2. Add responsive_image_route and set the value route/path/{file}/{size}, route/path can be whatever you want it to be, {file}/{size} can be anything you want to name them but both are required.

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.

fileableLoader.

The fileableLoader is responsible for mapping your model to the required collection and indicates that you want to use Laravel Filable to manage your model files.

The fileableLoader() method accepts an 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.

Single collection initialization.

Multiple collection initialization.

String parameter initialization.

The fileableLoader() method also accepts the key as a string first parameter and the value as a string as the second parameter.

Default media.

COnfigured default files are not loaded by default, to load the default file for the model, the fileableLoader exposes a third parameter, the useDefault parameter, setting it to true will ensure that your default file is loaded when the model's file is not found or missing.

OR

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 or system before the introduction of the fileable trait.

OR

Custom Database field.

There are times when you may want to use a different file name from your database field name, an instance could be when your request includes two diffrent file requests for different models that have the same database field names, the last parameter of the fileableLoader was added to support this scenario.

The 5th parameter of the fileableLoader is a string that should equal to the database field where you want your file reference stored in or an array that maps the request file name to the database field name.

Take a look at this example.

OR

OR

In the last example, cover_image is an existing database field mapped to the cover input request file name and image is an existing database field mapped to the admin_avatar input request file name.

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;

Manually saving files

You can also skip the interface and use the save method of Media library to manually create your files, the save method returns the name of the file as saved in your configured storage.

In the above example media is the target collection where your file should be saved while image is the name of the input from the request holding your file.

Manually saving from wildcard request array.

Consider the following scenario in a controller.

What we have done is save the files from within a loop, the 4th parameter of the save method [index] indicates where the file we want to save can be found in the requests uploaded file list.

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

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-fileable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2|^8.3
illuminate/filesystem Version ^9.0|^10.0|^11.0
illuminate/support Version ^9.0|^10.0|^11.0
imanghafoori/php-imports-analyzer Version ^1.0
intervention/image Version ^3.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package toneflix-code/laravel-fileable contains the following files

Loading the files please wait ....