Пример #1
0
 /**
  * Store a newly created resource in storage.
  * POST /adminimages
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Image::$rules);
     if ($validator->fails()) {
         //return Redirect::back()->withErrors($validator)->withInput();
         return Response::json('Upload Error', 400);
     }
     if ($data['code'] !== 0) {
         $building = Building::where('code', '=', $data['code'])->firstOrFail();
         $building_id = $building->id;
     } else {
         $building_id = '0';
     }
     $file = Input::file('file');
     $img_destination = 'public/assets/uploads/img/';
     $extension = $file->getClientOriginalExtension();
     $img_name = rand(11111, 99999) . '.' . $extension;
     $data = array('file' => $img_name, 'building_id' => $building_id);
     //dd($building->id);
     $upload = $file->move($img_destination, $img_name);
     if ($upload) {
         Image::create($data);
         return Response::json($file, 200);
     }
     return Response::json('error', 400);
     //return Redirect::route('admin.images');
 }