catch_phrase; $catchColor = $request->catch_color; $title = $request->title; $titleColor = $request->title_color; $picture = $request->picture; $picture_r = $request->picture_r; $linkLabel = $request->link_label; $link = $request->link; $linkColor = $request->link_color; $newTab = $request->new_tab === null ? 0 : 1; $day1 = $request->day1 === null ? 0 : 1; $day2 = $request->day2 === null ? 0 : 1; $day3 = $request->day3 === null ? 0 : 1; $day4 = $request->day4 === null ? 0 : 1; $day5 = $request->day5 === null ? 0 : 1; $day6 = $request->day6 === null ? 0 : 1; $day7 = $request->day7 === null ? 0 : 1; $status = 0; $request->validate([ 'catch_phrase' => 'required|max:100', 'catch_color' => 'required|max:7', 'title' => 'required|max:100', 'title_color' => 'required|max:7', 'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1366,height=553', 'picture_r' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=500,height=671', 'link_label' => 'required|max:100', 'link' => 'required|max:255', 'link_color' => 'required|max:7', ]); $imageName = Str::slug($title) .'-le-gaulois.'.$picture->extension(); $picture->move(public_path('images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName); $imageName_r = Str::slug($title) .'-le-gaulois_r.'.$picture_r->extension(); $picture_r->move(public_path('images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName_r); $hsp = new HomeSliderPictures(); $hsp->catch_phrase = $catchPhrase; $hsp->catch_color = $catchColor; $hsp->title = $title; $hsp->title_color = $titleColor; $hsp->picture = date('Y') . '/' . date('m') . '/' . $imageName; $hsp->picture_r = date('Y') . '/' . date('m') . '/' . $imageName_r; $hsp->link_label = $linkLabel; $hsp->link = $link; $hsp->link_color = $linkColor; $hsp->new_tab = $newTab; $hsp->day1 = $day1; $hsp->day2 = $day2; $hsp->day3 = $day3; $hsp->day4 = $day4; $hsp->day5 = $day5; $hsp->day6 = $day6; $hsp->day7 = $day7; $hsp->status = $status; $hsp->save(); return redirect()->route('bo.home-slider-pictures.index'); } public function edit($id) { $h = HomeSliderPictures::findOrFail($id); return view('bo.home-slider-pictures.edit', compact('h')); } public function update(Request $request, $id) { $catchPhrase = $request->catch_phrase; $catchColor = $request->catch_color; $title = $request->title; $titleColor = $request->title_color; $picture = $request->picture; $picture_r = $request->picture_r; $linkLabel = $request->link_label; $link = $request->link; $linkColor = $request->link_color; $newTab = $request->new_tab === null ? 0 : 1; $day1 = $request->day1 === null ? 0 : 1; $day2 = $request->day2 === null ? 0 : 1; $day3 = $request->day3 === null ? 0 : 1; $day4 = $request->day4 === null ? 0 : 1; $day5 = $request->day5 === null ? 0 : 1; $day6 = $request->day6 === null ? 0 : 1; $day7 = $request->day7 === null ? 0 : 1; $status = $request->status === null ? 0 : 1; $request->validate([ 'catch_phrase' => 'required|max:100', 'catch_color' => 'required|max:7', 'title' => 'required|max:100', 'title_color' => 'required|max:7', 'link_label' => 'required|max:100', 'link' => 'required|max:255', 'link_color' => 'required|max:7', ]); if ($picture !== NULL && $picture_r !== NULL){ $request->validate([ 'picture' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1366,height=553', 'picture_r' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=500,height=671', ]); }elseif ($picture !== NULL && $picture_r === NULL){ $request->validate([ 'picture' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1366,height=553' ]); }elseif ($picture === NULL && $picture_r !== NULL){ $request->validate([ 'picture_r' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=500,height=671' ]); } $hsp = HomeSliderPictures::findOrFail($id); if ($picture !== NULL){ if(file_exists(public_path('images/slider_accueil/') . $hsp->picture)) unlink(public_path('images/slider_accueil/') . $hsp->picture); $imageName = Str::slug($title) .'-le-gaulois.'.$picture->extension(); $picture->move(public_path('images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName); } if ($picture_r !== NULL) { if(file_exists(public_path('images/slider_accueil/') . $hsp->picture_r)) unlink(public_path('images/slider_accueil/') . $hsp->picture_r); $imageName_r = Str::slug($title) . '-le-gaulois_r.' . $picture_r->extension(); $picture_r->move(public_path('images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName_r); } $hsp->catch_phrase = $catchPhrase; $hsp->catch_color = $catchColor; $hsp->title = $title; $hsp->title_color = $titleColor; if ($picture !== null) $hsp->picture = date('Y') . '/' . date('m') . '/' . $imageName; if ($picture_r !== null) $hsp->picture_r = date('Y') . '/' . date('m') . '/' . $imageName_r; $hsp->link_label = $linkLabel; $hsp->link = $link; $hsp->link_color = $linkColor; $hsp->new_tab = $newTab; $hsp->day1 = $day1; $hsp->day2 = $day2; $hsp->day3 = $day3; $hsp->day4 = $day4; $hsp->day5 = $day5; $hsp->day6 = $day6; $hsp->day7 = $day7; $hsp->status = $status; $hsp->save(); return redirect()->route('bo.home-slider-pictures.edit', $hsp->id)->with('success', 'Enregistré !'); } public function destroy($id) { $h = HomeSliderPictures::findOrFail($id); if(file_exists(public_path('images/slider_accueil/') . $h->picture)) unlink(public_path('images/slider_accueil/') . $h->picture); if(file_exists(public_path('images/slider_accueil/') . $h->picture_r)) unlink(public_path('images/slider_accueil/') . $h->picture_r); $h->delete(); return redirect()->route('bo.home-slider-pictures.index'); } }