Download the PHP package cyneek/laravel-multiple-stapler without Composer

On this page you can find all versions of the php package cyneek/laravel-multiple-stapler. 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-multiple-stapler

Laravel Stapler Multiple File Handler

Spanish Readme

Index

Changes

v0.1.1

Changed the method hasAttachedFile into hasOneAttachedFile to improve compatibility with the CodeSleeve/laravel-stapler package. Now you can use both packages at the same time in your models.

Install

Add this package with composer with the following command:

After updating composer, add the service providers to the providers array in config/app.php.

From the command line, use the migration tool; it will make a basic table in charge of handling all the data from the files linked to the application Models.

Aaaaand it's done!

Description

Methods

The parameters that both methods accept are:

Configuration of Stapler properties

Declaring single file properties

This is the usual behavior in the Stapler library for Laravel. It lets uploading one single file and linking it into a loaded Model property, allowing all the usual operations that could be made in a vanilla Stapler file attachment.

To make a new property that links to a single file in a Model, you have to follow the next steps:

  1. Add the MultipleFileTrait trait into the model

  2. Add into the __construct() method the properties you want to add using hasOneAttachedFile method.

Warning: It's required to add the parameter creation methods BEFORE the construct parent calling.

Declaring multiple file properties

This behavior it's possible thanks to the polymorphyc tables from Laravel, they will store all the file data linking it with their parent Model objects thanks to the fields fileable_id, fileable_type and fileable_field that will store the parameter name.

To make a multiple file handler property in a model, you have to follow the next steps:

  1. Add the MultipleFileTrait trait into the model

  2. Add into the __construct() method the properties you want to add using hasMultipleAttachedFiles method.

Warning: It's required to add the parameter creation methods BEFORE the construct parent calling.

File insertion

Inserting files in single file properties

For this example we will use a form that will upload a single file into our Model property. It's possible to use form fields that accept multiple files, but in those cases, all except the first uploaded file will be automatically discarded.

You must keep in mind that when you are making an update operation with a form, if there is a previous file linked in that property, it will be automatically deleted if you upload a newer one.

Form view

Controller handler

This is the minimum code required to upload a file with a form and linking it into a new object Model. To learn about acessing file data, please read above in this Readme.

Inserting files in multiple file properties

It's required to have a Model with a file parameter capable of handling multiple files throught the hasMultipleAttachedFiles method.

Form view

Controller handler

As you can see, the only difference when working with multiple or single files it's in the Model definition and the form. The system will handle the storage of every uploaded file and will link it into the loaded Model.

Acessing uploaded file data

Acessing single file parameters

To access the linked file data from a loaded object, you only have to call it's parameter name as if it was a normal Laravel relation.

Acessing multiple file parameters

The only difference with this case in particular is that, instead of returning an Attached object as in the previous example, it will return a Collection with all the linked files, so you'll have to go over every file object as if it were an array if you want to interact with them.

Deleting linked files

You have to always keep in mind that, if you delete a parent object with attached linked files, those will also be automatically deleted, so:

Would delete the Example object with id 1 and all its linked files.

Explicit deletion of single file properties

It would be the same modus operandi as with the polymorphyc relations from Laravel.

Explicit deletion of multiple file properties

In this case, you'll need to go over every file object to delete it.

Known problems

There's a known Laravel 5.* issue that throws an exception while using php artisan while having installed the codesleeve/laravel-stapler package.

There's a solution for that in this issue


All versions of laravel-multiple-stapler with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
laravel/framework Version 4.*|5.*
codesleeve/laravel-stapler Version 1.0.*
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 cyneek/laravel-multiple-stapler contains the following files

Loading the files please wait ....