/**
  * Edit suggested restaurant
  *
  * @param $id
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function editSuggestedAction($id, Request $request)
 {
     if ($request->isMethod('GET')) {
         $data = array();
         $restaurant = RestaurantsSuggest::find($id);
         $categories = CategoriesCms::where('type', 'cuisine')->orderBy('name')->get();
         $data = array('restaurant' => $restaurant ? $restaurant : array(), 'categories' => $categories->toArray() ? $categories : array(), 'id' => $id, 'javascripts' => array('restaurant_suggest'), 'page_title' => 'Edit Suggested Restaurant');
         return view('cms.restaurant.suggested.edit', $data);
     } elseif ($request->isMethod('POST')) {
         extract($request->all());
         $errors = array();
         if (!$name) {
             $errors[] = 'Restaurant name is missing';
         }
         if (!$address) {
             $errors[] = 'Restaurant address is missing';
         }
         if (!$telephone) {
             $errors[] = 'Phone number is missing';
         }
         if (!$budget) {
             $errors[] = 'Budget is missing';
         }
         if ($budget && !is_numeric($budget)) {
             $errors[] = 'Budget is invalid';
         }
         if (!$latitude) {
             $errors[] = 'Latitude is missing';
         }
         if ($latitude && !is_numeric($latitude)) {
             $errors[] = 'Latitude is invalid';
         }
         if (!$longitude) {
             $errors[] = 'Longitude is missing';
         }
         if ($longitude && !is_numeric($longitude)) {
             $errors[] = 'Longitude is invalid';
         }
         if (!$operating_time) {
             $errors[] = 'Operating Time is missing';
         }
         if (!$cuisines) {
             $errors[] = 'Cuisines are missing';
         }
         if ($errors) {
             \Session::flash('errors', $errors);
             return redirect('cms/restaurant/suggested/edit/' . $id);
         }
         try {
             $restaurant = new RestaurantsSuggestCms();
             $restaurant->editRestaurantSuggest($id, $name, $address, $telephone, $budget, $latitude, $longitude, $operating_time, $credit_card, $smoking, $is_24hours, $can_dinein, $can_dineout, $can_deliver, $cuisines, $other_details);
             \Session::flash('success', 'Suggested Restaurant has been updated');
             return redirect('cms/restaurant/suggested/view/' . $id);
         } catch (Exception $e) {
             \Session::flash('errors', array('An unexpected error occured while trying to update suggested restaurant.'));
             return redirect('cms/restaurant/suggested/edit/' . $id);
         }
     }
 }
 /**
  * Add new category
  *
  * @param Request $request
  * @return \Illuminate\View\View
  * @throws \Exception
  */
 public function newAction(Request $request)
 {
     $data = array();
     $errors = array();
     $success = '';
     if ($request->isMethod('post')) {
         $params = $request->all();
         if (!$params['category_type']) {
             $errors[] = 'Category Type is required';
         } else {
             if (!in_array($params['category_type'], array('city', 'cuisine', 'mall'))) {
                 $errors[] = 'Invalid Category Type';
             }
         }
         if (!$params['category_name']) {
             $errors[] = 'Category Name is required';
         }
         if (!$errors) {
             $connection = DB::connection();
             try {
                 $connection->beginTransaction();
                 $category = new CategoriesCms();
                 $category->addCategory($params['category_type'], $params['category_name']);
                 $connection->commit();
                 $success = 'Category has been successfully added';
             } catch (Exception $e) {
                 $connection->rollBack();
                 $errors[] = $e->getMessage();
             }
         }
     }
     $data = array('errors' => $errors, 'success' => $success);
     return view('cms.category.new', $data);
 }