PHPackages                             hollogram/laravel-stapler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. hollogram/laravel-stapler

ActiveLibrary[File &amp; Storage](/categories/file-storage)

hollogram/laravel-stapler
=========================

Easy file upload management for the Laravel Framework.

v1.0.11(8y ago)08091MITPHPPHP &gt;=5.4.0

Since Jun 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/hollogram/laravel-stapler)[ Packagist](https://packagist.org/packages/hollogram/laravel-stapler)[ RSS](/packages/hollogram-laravel-stapler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (14)Used By (0)

laravel-stapler
===============

[](#laravel-stapler)

[![Latest Stable Version](https://camo.githubusercontent.com/f73d6efbf1c2ce1aec04570c400d7605f2ba93bc91a231ad95b3ee80cb96283e/68747470733a2f2f706f7365722e707567782e6f72672f636f6465736c656576652f6c61726176656c2d737461706c65722f762f737461626c652e737667)](https://packagist.org/packages/codesleeve/laravel-stapler)[![Total Downloads](https://camo.githubusercontent.com/33f14e6774fa184c95dc63886e4a508aeb5ea1d58430b64e6064a7bd40741733/68747470733a2f2f706f7365722e707567782e6f72672f636f6465736c656576652f6c61726176656c2d737461706c65722f646f776e6c6f6164732e737667)](https://packagist.org/packages/codesleeve/laravel-stapler)[![Latest Unstable Version](https://camo.githubusercontent.com/dde1db388cfde2c65435a7d6fa95bfe5a1310731a1b12d18858a829538c85647/68747470733a2f2f706f7365722e707567782e6f72672f636f6465736c656576652f6c61726176656c2d737461706c65722f762f756e737461626c652e737667)](https://packagist.org/packages/codesleeve/laravel-stapler)[![License](https://camo.githubusercontent.com/17e27f8fe1e75cb569fb10ec35aec7441df68aa15159c899874d16f598ea4ce8/68747470733a2f2f706f7365722e707567782e6f72672f636f6465736c656576652f6c61726176656c2d737461706c65722f6c6963656e73652e737667)](https://packagist.org/packages/codesleeve/laravel-stapler)

Laravel-Stapler is a Stapler-based file upload package for the Laravel framework. It provides a full set of Laravel commands, a migration generator, and a cascading package config on top of the [Stapler](https://github.com/CodeSleeve/stapler) package. It also bootstraps Stapler with very sensible defaults for use with Laravel. If you are wanting to use [Stapler](https://github.com/CodeSleeve/stapler) with Laravel, it is strongly recommended that you use this package to do so.

Laravel-Stapler was created by [Travis Bennett](https://twitter.com/tandrewbennett).

- [Requirements](#requirements)
- [Installation](#installation)
- [Deprecations](#deprecations)
- [Migrating From Stapler v1.0.0-Beta4](#migrating-from-Stapler-v1.0.0-Beta4)
- [Quick Start](#quickstart)
- [Commands](#commands)
    - [Fasten](#fasten)
    - [Refresh](#refresh)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)

Requirements
------------

[](#requirements)

This package currently requires php &gt;= 5.4 as well as Laravel &gt;= 4. If you're going to be performing image processing as part of your file upload, you'll also need GD, Gmagick, or Imagick (your preference) installed as part of your php environment.

Installation
------------

[](#installation)

Laravel-Stapler is distributed as a composer package, which is how it should be used in your app.

Install the package using Composer. Edit your project's `composer.json` file to require `codesleeve/laravel-stapler`.

```
  "require": {
    "laravel/framework": "4.*",
    "hollogram/laravel-stapler": "1.0.*"
  }
```

Once this operation completes, the final step is to add the service provider.

For Laravel 4, Open `app/config/app.php`, and add a new item to the providers array:

```
    'Hollogram\LaravelStapler\Providers\L4ServiceProvider'
```

For Laravel 5, Open `config/app.php`, and add a new item to the providers array:

```
    'Hollogram\LaravelStapler\Providers\L5ServiceProvider'
```

Deprecations
------------

[](#deprecations)

As of 1.0.04, the 'Hollogram\\LaravelStapler\\LaravelStaplerServiceProvider' service provider has been deprecated (this provider will be removed in the next major release). Instead, you should now be using the corresponding service provider for the specific version of Laravel that you're using.

migrating-from-Stapler-v1.0.0-Beta4
-----------------------------------

[](#migrating-from-stapler-v100-beta4)

If you've been using Stapler (prior to v1.0.0-Beta4) in your Laravel app, you now need to be using this package instead. Uninstall Stapler (remove it from your composer.json, remove the service provider, etc) and install this package following the instructions above. Once installed, the following changes may need need to be made in your application:

- In your models that are using Stapler, change `use Hollogram\Stapler\Stapler` to `use Hollogram\Stapler\ORM\EloquentTrait`. Your models will also need to implement `Hollogram\Stapler\ORM\StaplerableInterface`.
- If you published stapler's config, you'll need to rename config folder from `app/config/packages/codesleeve/stapler` to `app/config/packages/codesleeve/laravel-stapler`.
- Image processing libraries are now referenced by their full class name from the [Imagine Image](https://github.com/avalanche123/Imagine) package (e.g `gd` is now reference by `Imagine\Gd\Imagine`).
- In your s3 configuration, instead of passing 'key', 'secret', 'region', and 'scheme' options, you'll now need to pass a single 's3\_client\_config' array containing these options (and any others you might want). These will be passed directly to the s3ClientFactory when creating an S3 client. Passing the params as an array now allows you to configure your s3 client (for a given model/attachment) however you like. See:
- In your s3 configuration, instead of passing 'Bucket' and 'ACL', you'll now need to pass a single 's3\_object\_config' array containing these values (this is used by the S3Client::putObject() method). See: [http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#\_putObject](http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#_putObject)
- The ':laravel\_root' interpolation has been changed to ':app\_root'

Quickstart
----------

[](#quickstart)

In the document root of your application (most likely the public folder), create a folder named system and grant your application write permissions to it. For this, we're assuming the existence of an existing `User` model in which we're going to add an avatar image to.

In your model:

```
use Hollogram\Stapler\ORM\StaplerableInterface;
use Hollogram\Stapler\ORM\EloquentTrait;

class User extends Eloquent implements StaplerableInterface {
	use EloquentTrait;

	// Add the 'avatar' attachment to the fillable array so that it's mass-assignable on this model.
	protected $fillable = ['avatar', 'first_name', 'last_name'];

	public function __construct(array $attributes = array()) {
		$this->hasAttachedFile('avatar', [
			'styles' => [
				'medium' => '300x300',
				'thumb' => '100x100'
			]
		]);

		parent::__construct($attributes);
	}
}
```

> Make sure that the `hasAttachedFile()` method is called right before `parent::__construct()` of your model.

From the command line, use the migration generator:

```
php artisan stapler:fasten users avatar
php artisan migrate
```

In your new view:

```
