Exemplo n.º 1
0
 public function HomegridsStore($homegrid_no)
 {
     // ------------------------------------------------------------------------------------------------------------
     // EDIT HOME GRID
     // ------------------------------------------------------------------------------------------------------------
     if (!$homegrid_no || !is_numeric($homegrid_no) || $homegrid_no < 1 || $homegrid_no > 12) {
         return App::abort(404);
     }
     // ------------------------------------------------------------------------------------------------------------
     // LOAD HOMEGRID
     // ------------------------------------------------------------------------------------------------------------
     $homegrid = HomegridSetting::homegrid($homegrid_no)->first();
     if (!$homegrid) {
         $homegrid = new HomegridSetting(['name' => 'homegrid_' . str_pad($homegrid_no, 2, '0', STR_PAD_LEFT), 'since' => \Carbon\Carbon::now()]);
     } else {
         $homegrid->name = 'homegrid_' . str_pad($homegrid_no, 2, '0', STR_PAD_LEFT);
     }
     // ------------------------------------------------------------------------------------------------------------
     // PROCESS INPUT
     // ------------------------------------------------------------------------------------------------------------
     $rules['type'] = ['required', 'in:' . implode(',', \App\HomegridSetting::getType())];
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return redirect()->back()->withInput()->withErrors($validator);
     } else {
         $homegrid->type = Input::get('type');
         $homegrid->title = Input::get('title');
         $homegrid->destination = '';
         $homegrid->image_url = '';
         $homegrid->script = '';
         $homegrid->tag = '';
         $homegrid->label = Input::get('label');
         $homegrid->image_url = Input::get('image_url');
         $homegrid->show_title = Input::get('show_title') == 1 ? true : false;
         switch (Input::get('type')) {
             case 'destination':
             case 'featured_destination':
                 $homegrid->destination = Input::get('destination');
                 break;
             case 'tour_tags':
                 $homegrid->tag = Input::get('tag');
                 break;
             case 'script':
                 $homegrid->script = Input::get('script');
                 break;
             case 'link':
                 $homegrid->link = Input::get('link');
                 break;
         }
         if (!$homegrid->save()) {
             return redirect()->back()->withInput()->withErrors($homegrid->getErrors());
         } else {
             return redirect()->route('admin.' . $this->route_name . '.index', ['id' => $data->id])->with('alert_success', '"Grid #' . $homegrid_no . '" has been saved successfully');
         }
     }
     // ------------------------------------------------------------------------------------------------------------
     // SHOW DISPLAY
     // ------------------------------------------------------------------------------------------------------------
     $this->layout->page = view($this->page_base_dir . 'homegrids.create')->with('route_name', $this->route_name)->with('view_name', $this->view_name);
     $this->layout->page->homegrid = $homegrid;
     return $this->layout;
 }