芝麻web文件管理V1.00
编辑当前文件:/home/digitalh/public_html/app/Http/Controllers/Admin/VideoSectionController.php
id)->where('style', $style)->first(); return view('admin.sections.video.create', compact('favicon', 'panel_image','item_section', 'style')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // Form validation $validator = Validator::make($request->all(), [ 'style' => 'in:style1', 'video_type' => 'in:youtube,other', '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/video/'; // Make image name $image_name = time().'-'.$image->getClientOriginalName(); // Original size upload file $image->move($folder, $image_name); // Set input $input['section_image']= $image_name; } else { // Set input $input['section_image']= null; } // Record to database VideoSection::firstOrCreate([ 'language_id' => getLanguage()->id, 'style' => $input['style'], 'section_image' => $input['section_image'], 'video_type' => $input['video_type'], 'video_url' => $input['video_url'], 'title' => Purifier::clean($input['title']), ]); // Set a success toast, with a title toastr()->success('content.created_successfully', 'content.success'); return redirect()->route('video.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', 'video_type' => 'in:youtube,other', '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(); } $item_section = VideoSection::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/video/'; // Make image name $image_name = time().'-'.$image->getClientOriginalName(); // Delete Image File::delete(public_path($folder.$item_section->section_image)); // Original size upload file $image->move($folder, $image_name); // Set input $input['section_image']= $image_name; } // XSS Purifier $input['title'] = Purifier::clean($input['title']); // Update model VideoSection::find($id)->update($input); // Set a success toast, with a title toastr()->success('content.updated_successfully', 'content.success'); return redirect()->route('video.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 = VideoSection::find($id); // Folder path $folder = 'uploads/img/video/'; // Delete Image File::delete(public_path($folder.$item_section->section_image)); // Update Image VideoSection::find($id)->update(['section_image' => null]); // Set a success toast, with a title toastr()->success('content.deleted_successfully', 'content.success'); return redirect()->route('video.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 = VideoSection::find($id); // Folder path $folder = 'uploads/img/video/'; // 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('video.create', $item_section->style); } }