/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id ID of the background to update * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // Get selected background $background = Background::find($id); if ($background == null) { return redirect()->route('dashboard.settings.backgrounds.index')->with('message', 'Error: Background not found'); } $btnRemoveColour = $request->input('btnRemoveColour'); // Check if the user wants to just remove the background colour. if (isset($btnRemoveColour)) { $background->hex_colour = ""; $background->save(); return redirect()->route('dashboard.settings.backgrounds.index')->with('message', 'Background colour removed!'); } // Get request inputs $txtBackgroundName = $request->input('txtBackgroundName'); $hexBackgroundColor = $request->input('hexBackgroundColor'); // Validation $data = array('txtBackgroundName' => $txtBackgroundName); $rules = array('txtBackgroundName' => 'required|min:1|max:40|unique:background,name,' . $id); // Validate inputs $reponse = Helper::validator($data, $rules, 'dashboard.settings.backgrounds.index'); if (isset($reponse)) { return $reponse; } $background->name = $txtBackgroundName; // Upload image 1 $imageInput = Input::file('filBackgroundImage'); if ($imageInput != null) { $imagePath = Media::processMedia($imageInput, 'advert_backgrounds/'); // If we have a valid image then set the path in the database if ($imagePath != null) { $background->image_path = $imagePath; } } $background->hex_colour = $hexBackgroundColor; $background->save(); // Update return redirect()->route('dashboard.settings.backgrounds.index')->with('message', 'Background updated successfully'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $adID ID of the advert the page belongs to * @param int $id ID of the page to update * @return \Illuminate\Http\Response */ public function update(Request $request, $adID, $id) { $txtHeading = $request->input('txtPageName'); $txtContent = $request->input('txtPageContent'); $templateID = $request->input('txtTemplate'); $txtTransition = $request->input('drpTransitions'); $txtDirection = $request->input('drpTransitionDirection'); $data = array('txtPageName' => $txtHeading, 'txtContent' => $txtContent, 'txtTemplate' => $templateID); $rules = array('txtPageName' => 'max:255', 'txtContent' => 'max:255', 'txtTemplate' => 'required|exists:template,id'); // Validate input $response = Helper::validator($data, $rules, 'dashboard.advert.edit', [$adID]); if (isset($response)) { return $response; } $page = Page::find($id); $page->template_id = $templateID; $page->transition = $txtTransition . $txtDirection; $page->save(); $pageData = $page->PageData; $pageData->heading = $txtHeading; $pageData->content = $txtContent; // Upload image 1 $imageInput = Input::file('filPageImage'); if ($imageInput != null) { $imagePath = Media::processMedia($imageInput, 'advert_images/'); // If we have a valid image then set the path in the database if ($imagePath != null) { $pageData->image_path = $imagePath; } } $videoInput = Input::file('filPageVideo'); if ($videoInput != null) { $videoPath = Media::processMedia($videoInput, 'advert_videos/'); // If we have a valid image then set the path in the database if ($videoPath != null) { $pageData->video_path = $videoPath; } } $pageData->save(); $btnSaveClose = $request->input('btnSaveClose'); $btnNext = $request->input('btnNext'); if (isset($btnSaveClose)) { return redirect()->route('dashboard.advert.edit', [$adID])->with('message', 'Page saved!'); } if (isset($btnNext)) { return redirect()->route('dashboard.advert.{adID}.page.create', [$adID])->with('message', 'Page saved! And new page created!'); } return redirect()->route('dashboard.advert.{adID}.page.show', [$adID, $page->id])->with('message', 'Page created successfully'); }