translucent / s3-observer
此包已被废弃且不再维护。未建议替代包。
同步Eloquent与Amazon S3的观察者
v0.4.2
2014-01-23 04:43 UTC
Requires
- php: >=5.4.0
- aws/aws-sdk-php: 2.5.*
- illuminate/database: 4.1.x
- illuminate/support: 4.1.x
- intervention/image: 1.5.*
Requires (Dev)
- mockery/mockery: dev-master@dev
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2022-03-14 13:52:05 UTC
README
您可以使用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();
现在上传的文件在Amazon S3上!
如何使用
使用前
在使用S3Observer之前,您需要设置aws/aws-sdk-php-laravel
安装
在composer.json中需要translucent/s3-observer
{ "require": { "translucent/s3-observer": "0.4.*" } }
配置
为了使用S3Observer,更新设置文件。
php artisan config:publish translucent/s3-observer
示例配置
return array( 'public' => true, 'bucket' => '', 'base' => null, 'acl' => null, );
将S3Observer提供者和外观(可选)添加到app/config/app.php
'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('/'); }
更多信息
要查看更多信息,请检查Wiki!
许可
在MIT许可下。
© Kento Moriwaki 2014.