Exemplo n.º 1
0
 /**
  * Edit a restaurant
  *
  * @param $id
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function editAction($id, Request $request)
 {
     if ($request->isMethod('GET')) {
         $data = array();
         $restaurant = Restaurants::find($id);
         $data = array('restaurant' => $restaurant ? $restaurant : array(), 'id' => $id, 'javascripts' => array('restaurant'), 'page_title' => 'Edit Restaurant');
         return view('cms.restaurant.edit', $data);
     } elseif ($request->isMethod('POST')) {
         extract($request->all());
         $errors = array();
         if (!$restaurant_name) {
             $errors[] = 'Restaurant name is missing';
         }
         if (!$restaurant_address) {
             $errors[] = 'Restaurant address is missing';
         }
         if (!$restaurant_telephone) {
             $errors[] = 'Phone number is missing';
         }
         if (!$restaurant_budget) {
             $errors[] = 'Budget is missing';
         }
         if ($restaurant_budget && !is_numeric($restaurant_budget)) {
             $errors[] = 'Budget is invalid';
         }
         if (!$restaurant_latitude) {
             $errors[] = 'Latitude is missing';
         }
         if ($restaurant_latitude && !is_numeric($restaurant_latitude)) {
             $errors[] = 'Latitude is invalid';
         }
         if (!$restaurant_longitude) {
             $errors[] = 'Longitude is missing';
         }
         if ($restaurant_longitude && !is_numeric($restaurant_longitude)) {
             $errors[] = 'Longitude is invalid';
         }
         if ($errors) {
             \Session::flash('errors', $errors);
             return redirect('cms/restaurant/edit/' . $id);
         }
         try {
             $restaurant = new RestaurantsCms();
             $restaurant->editRestaurant($id, $restaurant_name, $restaurant_address, $restaurant_telephone, $restaurant_budget, $restaurant_latitude, $restaurant_longitude);
             \Session::flash('success', 'Restaurant has been updated');
             return redirect('cms/restaurant/view/' . $id);
         } catch (Exception $e) {
             \Session::flash('errors', array('An unexpected error occured while trying to update restaurant.'));
             return redirect('cms/restaurant/edit/' . $id);
         }
     }
 }