Download the PHP package phoenixfire296/laravel-attachments without Composer

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

Laravel 5.x file attachment helpers

This package allows to quickly links files to models.

Can also be installed on Laravel 5.4, see below

Installation

You can install this package via composer. Laravel 5.5+ auto discovers the service provider.

composer require bnbwebexpertise/laravel-attachments

Older Laravel 5.4 install

For 5.4 support install version 0.0.16 :

composer require bnbwebexpertise/laravel-attachments:0.0.16

Then add the service provider to your configuration :

Configuration

You can customize this package behavior by publishing the configuration file :

php artisan vendor:publish --provider='Bnb\Laravel\Attachments\AttachmentsServiceProvider'

Add attachments to a model class

Add the HasAttachment trait to your model class :

Then use it to bind a file to an instance :

Retrieve model's attachments

Regroup model's attachments

The group attribute allows to group attachements. The attachementsGroup method provided by the HasAttachment trait returns all the attachments with the given group value.

Delete an attachment

Calling the delete() method on an attachment model instance will delete the database row and the file. The deletion of the file can be disabled by setting the behaviors.cascade_delete to false in the configuration.

Not that calling delete() on a query() like statement will not cascade to the filesystem because it will not call the delete() method of the Attachment model class.

Hooking the file output

The Bnb\Laravel\Attachments\Attachment model class provides an outputting event that you can observe.

In the application service provider you could write for example :

Dropzone

Upload

This package provides a server endpoint for Dropzone.js or equivalent via the attachments.dropzone route alias.

It returns the attachment uuid along other fields as a JSON response. This value can be sent back later to the server to bind it to a model instance (deferred saving).

The form :

The response :

Send it back later :

Bind the value later :

Delete

The route attachments.dropzone.delete can be called via HTTP DELETE. The attachment ID must be provided as parameter.

The delete action provided by this route only works for pending attachement (not bound to a model).

To prevent deletion of other users file, the current CSRF token is saved when uploading via the dropzone endpoint and it must be the same when calling the dropzone delete endpoint. This behavior can be deactivated via the configuration or env key (see config/attachments.php).

Usage example :

Events

Two event are fired by the dropzone endpoints controller :

If one of the listeners returns false, the action is aborted.

Temporary URLs

It is possible to generate a unique temporary URL for downloading the attachments via the getTemporaryUrl method of the Attachment model, for sharing purposes foremost.
The getTemporaryUrl method has one parameter : a Carbon date, after which the link will no longer be valid.

The default generated URL is of the form : http://example.com/attachments/shared/<a very long string>. The share path can be modified in the config file under the shared_pattern key.

Cleanup commands

A command is provided to cleanup the attachments not bound to a model (when model_type and model_id are null).

php artisan attachment:cleanup

The -s (or --since=[timeInMinutes]) option can be set to specify another time limit in minutes : only unbound files older than the specified age will be deleted. This value is set to 1440 by default.

Customization

Set a custom database connection name for the models

You can customize the database connection name by either :

Extends Attachment model columns

The configuration defines the list of fillable attachment attributes in the attachment.attributes key.

This allows you to create migration to add new columns in the attachment table and declare them in your published config at config/attachments.php.

Customize the attachment storage directory prefix

You may easily customize the folder/prefix where new attachments are stored by either:

The default value is attachments and any trailing /s will be trimmed automatically.

Customize the attachment storage filepath

If you don't want to use the default storage filepath generation, you can provide the filepath option (relative to the root of storage disk). It must contain the directory and filename. It's up to you to ensure that the provided filepath is not in conflict with another file.

This does not apply to attachments uploaded via the integrated DropZone controller. Only available for explicit attachments.

Extending the Attachment model class

This can be helpful to add some relations to the attachment model.

Create your own model that extends Bnb\Laravel\Attachments\Attachment :

Bind your model to the Bnb\Laravel\Attachments\Contracts\AttachmentContract interface in a service provider :


All versions of laravel-attachments with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
illuminate/database Version 5.7.x|5.6.x|5.5.x
illuminate/routing Version 5.7.x|5.6.x|5.5.x
illuminate/support Version 5.7.x|5.6.x|5.5.x
illuminate/console Version 5.7.x|5.6.x|5.5.x
illuminate/encryption Version 5.7.x|5.6.x|5.5.x
bnbwebexpertise/php-uuid Version >=0.0.2
doctrine/dbal Version ~2.5
nesbot/carbon Version ~1.20
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 phoenixfire296/laravel-attachments contains the following files

Loading the files please wait ....