/** * Store a newly created hotel in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Hotel::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $hotel = new Hotel(); $hotel->nome_br = $data['nome_br']; $hotel->nome_en = $data['nome_en']; $hotel->descricao_br = $data['descricao_br']; $hotel->descricao_en = $data['descricao_en']; $hotel->estrelas = $data['estrelas']; $hotel->pais_id = $data['pais_id']; $hotel->valor = $data['valor']; $hotel->cidade = $data['cidade']; //$hotel->estado = $data['estado']; $hotel->publicado = $data['publicado']; if (Input::hasFile('imagem')) { $up_success = $this->uploadImage(Input::file('imagem'), 'hoteis'); if ($up_success) { $hotel->imagem = $up_success['filename']; } } $hotel->save(); if (Input::has('caracteristicas')) { $hotel->caracteristicas()->sync(Input::get('caracteristicas')); } if (Input::hasFile('imagens')) { $imagens = Input::file('imagens'); foreach ($imagens as $img) { $imginfo = $this->uploadImage($img, 'hoteis'); if ($imginfo) { $imagem = new Imagem(); $imagem->nome = $imginfo['filename']; $imagem->caminho = $imginfo['destinationPath']; $hotel->imagens()->save($imagem); } } } return Redirect::to('admin/hotel/')->with('success', array('Registro salvo.')); }