PHP code example of translucent / s3-observer

1. Go to this page and download the library: Download translucent/s3-observer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

translucent / s3-observer example snippets


$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();

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

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

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);
}

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('/');
}
bash
php artisan config:publish translucent/s3-observer