public function __construct()
 {
     $this->site_infos = Site_infos::first();
     $this->destination = Country::select('id', 'name', 'url')->where('status', 'Active')->get();
     $this->menu = Page::where('status', 'Active')->where('parent_id', 0)->where('status', 'Active')->get();
     /**
      * find parent id on the menu and concatenate related sub menu to Array
      * */
     foreach ($this->menu as $key => $m) {
         $this->menu[$key]->sub_menu = Page::where('parent_id', $m->id)->where('status', 'Active')->get()->toArray();
     }
     /**
      * find the country related category
      */
     foreach ($this->destination as $key => $d) {
         $this->destination[$key]->category = category::select('name', 'url')->where('country_id', $d->id)->where('status', 'Active')->get()->toArray();
     }
 }
 protected function __checkForDuplicateUul($id, $url)
 {
     if (Country::where('id', '!=', $id)->where('url', $url)->count() == 0) {
         return true;
     }
     return false;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request $request
  * @param  int $id
  * @return Response
  */
 public function UpdateAction(Request $request, $id)
 {
     $this->category = category::find($id);
     if ($this->category) {
         $url = MyHelper::clean(Input::get('name'));
         $this->country = Country::find(Input::get('country_id'));
         if (!$this->country) {
             return redirect()->back()->with('message', Lang::get('response.CUSTOM_MESSAGE_WARNING', ['message' => 'Country ID did not match']));
         }
         if ($this->__checkForDuplicateUrl($id, $this->country->id, $url)) {
             if ($request->hasfile('image')) {
                 $file = $request->file('image');
                 $image_name = $file->getClientOriginalName();
                 $rand = rand(5000, 60000) . '_';
                 $new_img_name = $rand . $image_name;
                 $get_old_image = $this->category->image;
                 if (!File::exists($this->image_path)) {
                     return redirect()->back()->with('message', Lang::get('response.CUSTOM_MESSAGE_WARNING', ['message' => 'No image Folder']));
                 }
                 @unlink($this->image_path . '/' . $get_old_image);
                 $file->move($this->image_path, $new_img_name);
                 $this->category->country_id = $request->get('country_id');
                 $this->category->name = $request->get('name');
                 $this->category->url = $url;
                 $this->category->image = $new_img_name;
                 $this->category->short_description = $request->get('short_description');
                 $this->category->detail_description = $request->get('detail_description');
                 $this->category->status = $request->get('status');
                 $this->category->save();
                 return redirect()->route('category/list')->with('message', Lang::get('response.CUSTOM_MESSAGE_SUCCESS', ['message' => 'The category field is successfully updated']));
             }
             $this->category->country_id = $request->get('country_id');
             $this->category->name = $request->get('name');
             $this->category->url = $url;
             $this->category->short_description = $request->get('short_description');
             $this->category->detail_description = $request->get('detail_description');
             $this->category->status = $request->get('status');
             $this->category->save();
             return redirect()->route('category/list')->with('message', Lang::get('response.CUSTOM_MESSAGE_SUCCESS', ['message' => 'The category has been Updated']));
         }
         return redirect()->back()->with('message', Lang::get('response.CUSTOM_MESSAGE_WARNING', ['message' => 'Duplicate  Url supply']));
     }
     return redirect()->back()->with('message', Lang::get('response.CUSTOM_MESSAGE_WARNING', ['message' => 'Invalid request supply']));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request $request
  * @param  int $id
  * @return Response
  */
 public function UpdateAction(Request $request, $id)
 {
     /* MyHelper::debug(Input::all(),1);die;*/
     $this->package = Package::find($id);
     if (!$this->package) {
         return redirect()->back()->withInput()->with('message', Lang::get('response.CUSTOM_MESSAGE_ALERT', ['message' => 'Invalid Package id']));
     }
     $this->country = Country::find($request->get('country_id'));
     if (!$this->country) {
         return redirect()->back()->withInput()->with('message', Lang::get('response.CUSTOM_MESSAGE_ALERT', ['message' => 'Invalid Country id']));
     }
     $this->category = category::find($request->get('category_id'));
     if (!$this->category) {
         return redirect()->back()->withInput()->with('message', Lang::get('response.CUSTOM_MESSAGE_ALERT', ['message' => 'Invalid Category id']));
     }
     $url = MyHelper::clean($request->get('title'));
     $rand = rand(20000, 300000) . '_';
     if ($this->__checkForDuplicate_url($id, $this->category->id, $url)) {
         if ($request->hasfile('image')) {
             $file = $request->file('image');
             $image_name = $file->getClientOriginalName();
             $image_new_name = $rand . $image_name;
             $find_old_image = $this->package->image;
             @unlink($this->image_path . '/' . $find_old_image);
             if (!File::exists($this->image_path)) {
                 return redirect()->back()->withInput()->with('message', Lang::get('response.CUSTOM_MESSAGE_ALERT', ['message' => 'Image Folder not found']));
             }
             $file->move($this->image_path, $image_new_name);
             $this->package->category_id = $request->get('category_id');
             $this->package->title = $request->get('title');
             $this->package->url = $url;
             $this->package->image = $image_new_name;
             $this->package->is_special = $request->get('is_special');
             $this->package->grade = $request->get('grade');
             $this->package->currency = $request->get('currency');
             $this->package->price = $request->get('price');
             $this->package->route = $request->get('route');
             $this->package->duration = $request->get('duration');
             $this->package->itinerary = $request->get('itinerary');
             $this->package->const_description = $request->get('const_description');
             $this->package->short_description = $request->get('short_description');
             $this->package->detail_description = $request->get('detail_description');
             $this->package->status = $request->get('status');
             $this->package->save();
         }
         $this->package->category_id = $request->get('category_id');
         $this->package->title = $request->get('title');
         $this->package->url = $url;
         $this->package->is_special = $request->get('is_special');
         $this->package->grade = $request->get('grade');
         $this->package->currency = $request->get('currency');
         $this->package->price = $request->get('price');
         $this->package->route = $request->get('route');
         $this->package->duration = $request->get('duration');
         $this->package->itinerary = $request->get('itinerary');
         $this->package->const_description = $request->get('const_description');
         $this->package->short_description = $request->get('short_description');
         $this->package->detail_description = $request->get('detail_description');
         $this->package->status = $request->get('status');
         $this->package->save();
         return redirect()->route('package/list')->with('message', Lang::get('response.CUSTOM_MESSAGE_SUCCESS', ['message' => 'The package hasbeen successfully  updated']));
     }
     return redirect()->back()->withInput()->with('message', Lang::get('response.CUSTOM_MESSAGE_ALERT', ['message' => 'Duplicate  url']));
 }