translucent/s3-observer

This package is abandoned and no longer maintained. No replacement package was suggested.

Observer to sync your Eloquent with Amazon S3

v0.4.2 2014-01-23 04:43 UTC

This package is not auto-updated.

Last update: 2022-03-14 13:52:05 UTC


README

You can easily upload and delete images by S3Observer

$user = User::find($id);
$user->fill(Input::all());
if (Input::hasFile('profile_image')) {
    $user->profile_image = Input::file('profile_image');
}
if (Input::has('delete_profile_image')) {
    $user->profile_image = null;
}
$user->save();

Now the uploaded file is on Amazon S3!

How To Use

Before

You need setup aws/aws-sdk-php-laravel before use S3Observer

Installation

Require the translucent/s3-observer in your composer.json

{
    "require": {
        "translucent/s3-observer": "0.4.*"
    }
}

Configuration

In order to use S3Observer, update settings files.

php artisan config:publish translucent/s3-observer

Sample configuration

return array(
    'public' => true,
    'bucket' => '',
    'base' => null,
    'acl' => null,
);

Add S3Observer provider and facade(optional) to app/config/app.php

'providers' => array(
     // ...
    'Translucent\S3Observer\S3ObserverServiceProvider',
),
'aliases' => array(
    // ...
    'S3Observer' => 'Translucent\S3Observer\Facades\S3Observer',
)

Sample Usage

In your model,

protected static function boot()
{
    parent::boot();
    // Setup observer
    $observer = S3Observer::setUp('User', array(
        'bucket' => 'user-bucket'
    ));
    // Observe fields
    $observer->setFields('profile_image', 'thumbnail');
    // Fields configuration
    $observer->config('thumbnail.image', array(
        'width' => 150,
        'height' => 150
    ));
    static::observe($observer);
}

And in your controller...

public function postEdit($id)
{
    $user = User::findOrFail($id);
    $user->fill(Input::all());
    if (Input::hasFile('profile_image')) {
        $user->profile_image = Input::file('profile_image');
        $user->thumbnail = Input::file('profile_image');
    }
    if (Input::has('delete_profile_image')) {
        $user->profile_image = null;
				$user->thumbnail = null;
    }
    $user->save();
    return Redirect::to('/');
}

More information

To see more information, please check Wiki!

License

Under the MIT license.

© Kento Moriwaki 2014.