Esempio n. 1
0
 /**
  * Store a newly created Image in storage.
  *
  * @return Response
  */
 public function store()
 {
     // $a = '>>>|';
     // foreach (Request::all() as $key => $value) $a .=  $key . ':::' . $value . '|';
     // return $a;
     $valid_ext = ['jpg', 'png', 'bmp', 'gif', 'jpeg'];
     if (!Request::hasFile('image')) {
         throw new FileUploadException('image not found');
     }
     if (!Request::file('image')->isValid()) {
         throw new FileUploadException('image is not valid');
     }
     $params = Request::all();
     $file = $params['image'];
     unset($params['image']);
     if (!in_array($file->getClientOriginalExtension(), $valid_ext)) {
         throw new FileUploadException('image type is not valid');
     }
     $file_name = Carbon::now()->format('Ymd_His_') . $params['title'] . '.' . $file->getClientOriginalExtension();
     $file_path = 'images/';
     $params['filename'] = $file_name;
     $image = new Image($params);
     if ($image->save()) {
         Storage::put($file_path . $file_name, File::get($file));
         return $image;
     } else {
         throw new CrudException('image:store');
     }
 }
Esempio n. 2
0
 private function setUpObj()
 {
     $obj = new Image();
     $obj->title = 'title';
     $obj->slug = 'slug';
     $obj->filename = 'filename';
     $obj->description = 'description';
     $obj->save();
     return $obj;
 }
Esempio n. 3
0
 /**
  * Tes menambahkan Image
  */
 public function testAdd()
 {
     $obj = new Image();
     $obj->title = 'title';
     $obj->slug = 'slug';
     $obj->filename = 'filename';
     $obj->description = 'description';
     $saved = $obj->save();
     $this->assertTrue($saved);
     $obj_2 = Image::find($obj->id);
     if ($obj_2 !== null) {
         $this->assertEquals($obj, $obj_2);
     }
 }