Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Image extends Eloquent {
- public function products() {
- return $this->belongs_to('Product');
- }
- public static function input($product_id, $field = 'image', $directory='public/pictures')
- {
- $rules = array( $field => 'image' );
- $validator = Validator::make( Input::file(), $rules );
- if ($validator->fails())
- {
- return $validator->errors;
- }
- $file = Input::file( $field );
- $ext = pathinfo( $file['name'], PATHINFO_EXTENSION );
- $name = md5($file['name'] ) . '.' . $ext;
- $directory .= "/{$product_id}";
- Input::upload($field, $directory, $name);
- $image = new static;
- $image->product_id = $product_id;
- $image->filename = $name;
- $image->directory = $directory;
- return $image;
- }
- public function set_temporary( $temp )
- {
- $this->set_attribute('temp', (int) (bool) $temp );
- }
- }
Add Comment
Please, Sign In to add comment