Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Multiple files

KentoMoriwaki edited this page Jan 25, 2014 · 1 revision

To handle multiple files, in your Eloquent model

class Foobar extends Eloquent
{

	protected static function boot()
	{
		parent::boot();

		$observer = S3Observer::setUp('Foobar');
		$observer->setFields('profile', 'profile_thumb', 'cover_image');
		$observer->config('profile_thumb.image', array(
			'width' => 150,
			'height' => 150,
		));
		static::observe($observer);
	}

}

and in your controller or route

$id = 1;
$foobar = Foobar::find($id);
$foobar->fill(Input::all());
if (Input::hasFile('profile')) {
	$foobar->profile = Input::file('profile'); // Uploaded to /foo_bar/profile/1.{extension}
	$foobar->profile_thumb = Input::file('profile_thumb'); // foo_bar/profile_thumb/1.{extension}
}
if (Input::hasFile('cover_image')) {
	$foobar->cover_image = Input::file('cover_image'); // foo_bar/cover_image/1.{extension}
}
$foobar->save();

Now $foobar->profile == 'https://{your_bucket_domain}/foo_bar/profile/1.{extension}' and profile_thumb was croped and resized to 150x150.

Clone this wiki locally