芝麻web文件管理V1.00
编辑当前文件:/home/digitalh/www/app/Http/Controllers/Admin/WhyChooseSectionController.php
all(), [ 'style' => 'in:style1', 'section_image' => 'mimes:svg,png,jpeg,jpg,webp,gif|max:2048', ]); // Any error checking if ($validator->fails()){ toastr()->error($validator->errors()->first(), 'content.error'); return back(); } // Get All Request $input = $request->all(); if ($request->hasFile('section_image')) { // Get image file $image = $request->file('section_image'); // Folder path $folder ='uploads/img/why_choose/'; // Make image name $image_name = time().'-'.$image->getClientOriginalName(); // Upload image $image->move($folder, $image_name); // Set input $input['section_image']= $image_name; } else { // Set input $input['section_image']= null; } // Record to database WhyChooseSection::firstOrCreate([ 'language_id' => getLanguage()->id, 'style' => $input['style'], 'section_image' => $input['section_image'], 'section_title' => Purifier::clean($input['section_title']), 'title' => Purifier::clean($input['title']), 'description' => Purifier::clean($input['description']), 'item' => $input['item'], ]); // Set a success toast, with a title toastr()->success('content.created_successfully', 'content.success'); return redirect()->route('why-choose.create', $input['style']); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // Form validation $validator = Validator::make($request->all(), [ 'style' => 'in:style1', 'section_image' => 'mimes:svg,png,jpeg,jpg,webp,gif|max:2048', ]); // Any error checking if ($validator->fails()){ toastr()->error($validator->errors()->first(), 'content.error'); return back(); } // Get model $item_section = WhyChooseSection::find($id); // Get All Request $input = $request->all(); if ($request->hasFile('section_image')) { // Get image file $image = $request->file('section_image'); // Folder path $folder = 'uploads/img/why_choose/'; // Make image name $image_name = time().'-'.$image->getClientOriginalName(); // Delete Image File::delete(public_path($folder.$item_section->section_image)); // Upload image $image->move($folder, $image_name); // Set input $input['section_image'] = $image_name; } // XSS Purifier $input['section_title'] = Purifier::clean($input['section_title']); $input['title'] = Purifier::clean($input['title']); $input['description'] = Purifier::clean($input['description']); // Update model WhyChooseSection::find($id)->update($input); // Set a success toast, with a title toastr()->success('content.updated_successfully', 'content.success'); return redirect()->route('why-choose.create', $input['style']); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy_image($id) { // Retrieve a model $item_section = WhyChooseSection::find($id); // Folder path $folder = 'uploads/img/why_choose/'; // Delete Image File::delete(public_path($folder.$item_section->section_image)); // Update Image WhyChooseSection::find($id)->update(['section_image' => null]); // Set a success toast, with a title toastr()->success('content.deleted_successfully', 'content.success'); return redirect()->route('why-choose.create', $item_section->style); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // Retrieve a model $item_section = WhyChooseSection::find($id); // Folder path $folder = 'uploads/img/why_choose/'; // Delete Image File::delete(public_path($folder.$item_section->section_image)); $item_section->delete(); // Set a success toast, with a title toastr()->success('content.deleted_successfully', 'content.success'); return redirect()->route('why-choose.create', $item_section->style); } }