Advertisement
benshepherd

UploadPicture.php

Jul 25th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2.  
  3. class UploadPicture extends Eloquent
  4. {
  5.     //use PictureTrait, UploadTrait, PublishableTrait;
  6.     use PictureTrait;
  7.  
  8.     protected $table = 'uploads';
  9.  
  10.     protected $fillable = array(
  11.         'title',
  12.         'body',
  13.         'tags',
  14.     );
  15.  
  16.     public static function getRules($upload)
  17.     {
  18.         if($upload == null)
  19.         {
  20.             return array(
  21.                 'title' => 'required|min:10|max:100',
  22.                 'body' => 'required',
  23.                 'picture' => 'required|image|mimes:jpg,jpeg,png,gif|max:2500'
  24.             );
  25.         }
  26.         else
  27.         {
  28.             return array(
  29.                 'title' => 'required|min:10|max:100',
  30.                 'body' => 'required',
  31.                 'picture' => 'image|mimes:jpg,jpeg,png,gif|max:2500'
  32.             );
  33.         }
  34.     }
  35.  
  36.     public static function edit($upload)
  37.     {
  38.         if($upload == null) {
  39.             $upload = new UploadPicture;
  40.             $upload->type = 'picture';
  41.             $upload->user_id = Auth::id();
  42.         }
  43.  
  44.         $upload->fill(Input::all());
  45.  
  46.         if(Input::hasFile('picture')) {
  47.             $upload->uploadPicture();
  48.             $upload->createThumbnail();
  49.         }
  50.  
  51.         $upload->save();
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement