/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(TemplateRequest $request)
 {
     // Do we have an uploaded image?
     // Handle display image
     if ($request->hasFile('display_img')) {
         // Save file somewhere useful
         $path = public_path() . '/img/';
         $filename = $request->file('display_img')->getFilename() . '.' . $request->file('display_img')->guessExtension();
         $request->file('display_img')->move($path, $filename);
     }
     // Create the template group
     $group = TemplateGroup::create(['name' => $request['name'], 'type' => $request['type'], 'display_img' => isset($filename) ? $filename : '']);
     if ($request['templates']) {
         // We have some templates selected
         foreach ($request['templates'] as $id => $val) {
             if (0 == $val) {
                 // Template wasn't selected for inclusion
                 continue;
             }
             $template = new Template(['template_id' => $id, 'size' => 'SaaS' == $group->type ? '0' : $request['templateSize'][$id], 'price' => '0']);
             $group->templates()->save($template);
             unset($template, $id, $val);
         }
     }
     return redirect()->route('admin.template.index');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update($id, Requests\TemplateRequest $request)
 {
     $template = Templates::findorFail($id);
     $template->update($request->all());
     session()->flash('flash_message', 'Template Successfully Saved!');
     return redirect('templates/' . $id . '');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, TemplateRequest $requests)
 {
     if ($requests->active_state = 1) {
         $templates = Template::all();
         foreach ($templates as $template) {
             $template->active_state = 0;
             $template->save();
         }
     }
     $template = Template::findOrFail($id);
     $template->fill($requests->all());
     $template->modified_by = Auth::user()->id;
     $template->save();
     flash()->success('Template Updated.');
     return redirect('template');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(TemplateRequest $request, $id)
 {
     $input = $request->all();
     // Template update
     $template = Template::find($id);
     $updateTemplate = array('name' => $input['template_name'], 'display_name' => $input['template_display_name'], 'description' => $input['template_description'], 'category_id' => $input['template_category']);
     $template->update($updateTemplate);
     // Template sections update
     for ($i = 0; $i < count($input['section_name']); $i++) {
         $oneSection = array('name' => $input['section_name'][$i], 'display_name' => $input['section_display_name'][$i], 'description' => $input['section_description'][$i], 'content' => $input['section_content'][$i], 'is_editable' => $input['section_editable'][$i], 'template_id' => $id);
         $existedSection = TemplateSection::where('name', '=', $oneSection['name'])->get()->toArray();
         if ($existedSection) {
             $templateSection = TemplateSection::find($existedSection['id']);
             $templateSection->update($oneSection);
         } else {
             if ($oneSection['name']) {
                 TemplateSection::create($oneSection);
             }
         }
     }
     return redirect('home/template');
 }