2017 © Pedro Peláez
 

library s3-observer

Observer to sync your Eloquent with Amazon S3

image

translucent/s3-observer

Observer to sync your Eloquent with Amazon S3

  • Thursday, January 23, 2014
  • by KentoMoriwaki
  • Repository
  • 1 Watchers
  • 4 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Observer to sync your Eloquent with Amazon S3

You can easily upload and delete images by S3Observer, (*1)

$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!, (*2)

How To Use

Before

You need setup aws/aws-sdk-php-laravel before use S3Observer, (*3)

Installation

Require the translucent/s3-observer in your composer.json, (*4)

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

Configuration

In order to use S3Observer, update settings files., (*5)

php artisan config:publish translucent/s3-observer

Sample configuration, (*6)

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

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

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

Sample Usage

In your model,, (*8)

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

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!, (*10)

License

Under the MIT license., (*11)

© Kento Moriwaki 2014., (*12)

The Versions

23/01 2014

dev-master

9999999-dev

Observer to sync your Eloquent with Amazon S3

  Sources   Download

MIT

The Requires

 

The Development Requires

by (Kento Moriwaki)translucent-works

23/01 2014

v0.4.2

0.4.2.0

Observer to sync your Eloquent with Amazon S3

  Sources   Download

MIT

The Requires

 

The Development Requires

by (Kento Moriwaki)translucent-works

23/01 2014

dev-dev

dev-dev

Observer to sync your Eloquent with Amazon S3

  Sources   Download

MIT

The Requires

 

The Development Requires

by (Kento Moriwaki)translucent-works

22/01 2014

v0.4.1

0.4.1.0

Observer to sync your Eloquent with Amazon S3

  Sources   Download

The Requires

 

The Development Requires

by (Kento Moriwaki)translucent-works

18/01 2014

v0.4.0

0.4.0.0

Observer to sync your Eloquent with Amazon S3

  Sources   Download

The Requires

 

The Development Requires

by (Kento Moriwaki)translucent-works

16/01 2014

v0.3.0

0.3.0.0

  Sources   Download

The Requires

 

The Development Requires

by (Kento Moriwaki)translucent-works

13/01 2014

v0.2.0

0.2.0.0

  Sources   Download

The Requires

 

The Development Requires

by (Kento Moriwaki)translucent-works

13/01 2014

v0.1.0

0.1.0.0

  Sources   Download

The Requires

 

The Development Requires

by (Kento Moriwaki)translucent-works

12/01 2014

v0.0.0

0.0.0.0

  Sources   Download

The Requires

 

The Development Requires

by (Kento Moriwaki)translucent-works