2017 © Pedro Peláez
 

library lumen-stapler

Easy file upload management for the Lumen Framework.

image

expstudio/lumen-stapler

Easy file upload management for the Lumen Framework.

  • Monday, September 11, 2017
  • by expstudio
  • Repository
  • 1 Watchers
  • 0 Stars
  • 832 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 108 Forks
  • 0 Open issues
  • 15 Versions
  • 31 % Grown

The README.md

lumen-stapler

Latest Stable VersionTotal Downloads Latest Unstable Version License, (*1)

Lumen-Stapler is a Stapler-based file upload package for the Lumen framework. It provides a full set of Lumen commands, a migration generator, and a cascading package config on top of the Stapler package. It also bootstraps Stapler with very sensible defaults for use with Lumen. If you are wanting to use Stapler with Lumen, it is strongly recommended that you use this package to do so., (*2)

Lumen-Stapler was created by Watee Wichiennit., (*3)

Requirements

This package currently requires php >= 5.4 as well as Lumen >= 5.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., (*4)

Installation

Lumen-Stapler is distributed as a composer package, which is how it should be used in your app., (*5)

Install the package using Composer. Edit your project's composer.json file to require expstudio/Lumen-stapler., (*6)

  "require": {
    "laravel/lumen-framework": "5.4.*",
    "expstudio/lumen-stapler": "1.0.*"
  }

Once this operation completes, the final step is to add the service provider., (*7)

For Lumen 5.4, Open config/app.php, and add a new item to the providers array:, (*8)

    $app->register(Expstudio\LumenStapler\Providers\LumenStaplerServiceProvider::Class);
  • In your models that are using Stapler, change use Codesleeve\Stapler\Stapler to use Codesleeve\Stapler\ORM\EloquentTrait. Your models will also need to implement Codesleeve\Stapler\ORM\StaplerableInterface., (*9)

  • If you published stapler's config, you'll need to rename config folder from app/config/packages/expstudio/stapler to app/config/packages/expstudio/lumen-stapler., (*10)

  • Image processing libraries are now referenced by their full class name from the Imagine Image package (e.g gd is now reference by Imagine\Gd\Imagine)., (*11)

  • 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: http://docs.aws.amazon.com/aws-sdk-php/guide/latest/configuration.html#client-configuration-options, (*12)

  • 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, (*13)

  • The ':Lumen_root' interpolation has been changed to ':app_root', (*14)

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., (*15)

In your model:, (*16)

use Codesleeve\Stapler\ORM\StaplerableInterface;
use Codesleeve\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., (*17)

From the command line, use the migration generator:, (*18)

php artisan stapler:fasten users avatar
php artisan migrate

In your new view:, (*19)

<?= Form::open(['url' => action('UsersController@store'), 'method' => 'POST', 'files' => true]) ?>
    <?= Form::input('first_name') ?>
    <?= Form::input('last_name') ?>
    <?= Form::file('avatar') ?>
    <?= Form::submit('save') ?>
<?= Form::close() ?>

In your controller:, (*20)

public function store()
{
    // Create and save a new user, mass assigning all of the input fields (including the 'avatar' file field).
    $user = User::create(Input::all());
}

In your show view:, (*21)

<img src="<?= $user->avatar->url() ?>" >
<img src="<?= $user->avatar->url('medium') ?>" >
<img src="<?= $user->avatar->url('thumb') ?>" >

To detach (reset) a file, simply assign the constant STAPLER_NULL to the attachment and the save):, (*22)

$user->avatar = STAPLER_NULL;
$user->save();

This will ensure the the corresponding attachment fields in the database table record are cleared and the current file is removed from storage. The database table record itself will not be destroyed and can be used normally (or even assigned a new file upload) as needed., (*23)

Commands

fasten

This package provides a fasten command that can be used to generate migrations for adding image file fields to existing tables. The method signature for this command looks like this: php artisan stapler:fasten <tablename> <attachment>, (*24)

In the quickstart example above, calling php artisan stapler:fasten users avatar followed by php artisan migrate added the following fields to the users table:, (*25)

  • (string) avatar_file_name
  • (integer) avatar_file_size
  • (string) avatar_content_type
  • (timestamp) avatar_updated_at

refresh

The refresh command can be used to reprocess uploaded images on a model's attachments. It works by calling the reprocess() method on each of the model's attachments (or on specific attachments only). This is very useful for adding new styles to an existing attachment when a file has already been uploaded for that attachment., (*26)

Reprocess all attachments for the ProfilePicture model: php artisan stapler:refresh ProfilePicture, (*27)

Reprocess only the photo attachment on the ProfilePicture model: php artisan stapler:refresh TestPhoto --attachments="photo", (*28)

Reprocess a list of attachments on the ProfilePicture model: php artisan stapler:refresh TestPhoto --attachments="foo, bar, baz, etc", (*29)

Troubleshooting

Before you submit an issue or create a pull request, please take a look at the Troubleshooting Section section of the Stapler package. There's a very good chance that many (if not all) of the issues you're having with this package are related to the base stapler package and have already been addressed there., (*30)

Contributing

This package is always open to contributions:, (*31)

  • Master will always contain the newest work (bug fixes, new features, etc), however it may not always be stable; use at your own risk. Every new tagged release will come from the work done on master, once things have stablized, etc.

The Versions

11/09 2017

dev-master

9999999-dev

Easy file upload management for the Lumen Framework.

  Sources   Download

MIT

The Requires

 

by Watee Wichiennit

laravel file lumen s3 upload aws paperclip stapler

11/09 2017

v2.0.2

2.0.2.0

Easy file upload management for the Lumen Framework.

  Sources   Download

MIT

The Requires

 

by Watee Wichiennit

laravel file lumen s3 upload aws paperclip stapler

03/09 2017

v2.0.1

2.0.1.0

Easy file upload management for the Lumen Framework.

  Sources   Download

MIT

The Requires

 

by Watee Wichiennit

laravel file lumen s3 upload aws paperclip stapler

03/09 2017

v2.0.0

2.0.0.0

Easy file upload management for the Lumen Framework.

  Sources   Download

MIT

The Requires

 

by Watee Wichiennit

laravel file lumen s3 upload aws paperclip stapler

03/09 2017

v1.0.1

1.0.1.0

Easy file upload management for the Lumen Framework.

  Sources   Download

MIT

The Requires

 

by Watee Wichiennit

laravel file lumen s3 upload aws paperclip stapler

04/02 2017

dev-develop

dev-develop

Easy file upload management for the Laravel Framework.

  Sources   Download

MIT

The Requires

 

laravel file s3 upload aws paperclip stapler

04/02 2017

v1.0.08

1.0.08.0

Easy file upload management for the Laravel Framework.

  Sources   Download

MIT

The Requires

 

laravel file s3 upload aws paperclip stapler

30/01 2016

v1.0.07

1.0.07.0

Easy file upload management for the Laravel Framework.

  Sources   Download

MIT

The Requires

 

laravel file s3 upload aws paperclip stapler

19/01 2016

v1.0.06

1.0.06.0

Easy file upload management for the Laravel Framework.

  Sources   Download

MIT

The Requires

 

laravel file s3 upload aws paperclip stapler

21/09 2015

v1.0.05

1.0.05.0

Easy file upload management for the Laravel Framework.

  Sources   Download

MIT

The Requires

 

laravel file s3 upload aws paperclip stapler

20/07 2015

v1.0.04

1.0.04.0

Easy file upload management for the Laravel Framework.

  Sources   Download

MIT

The Requires

 

laravel file s3 upload aws paperclip stapler

04/02 2015

v1.0.03

1.0.03.0

Easy file upload management for the Laravel Framework.

  Sources   Download

MIT

The Requires

 

laravel file s3 upload aws paperclip stapler

28/09 2014

v1.0.02

1.0.02.0

Easy file upload management for the Laravel Framework.

  Sources   Download

MIT

The Requires

 

laravel file s3 upload aws paperclip stapler

12/06 2014

v1.0.01

1.0.01.0

Easy file upload management for the Laravel Framework.

  Sources   Download

MIT

The Requires

 

laravel file s3 upload aws paperclip stapler

11/06 2014

v1.0.0

1.0.0.0

Easy file upload management for the Laravel Framework.

  Sources   Download

MIT

The Requires

 

laravel file s3 upload aws paperclip stapler