img_path); $image_type_aux = explode("image/", $image_parts[0]); $image_type = $image_type_aux[1]; $image_base64 = base64_decode($image_parts[1]); $imageName = uniqid() . '.png'; $imageFullPath = $folderPath.$imageName; file_put_contents($imageFullPath, $image_base64); // for image upload end $manage_free_video = new ManageFreeVideo; $manage_free_video->video_type = $request->input('video_type'); $manage_free_video->video_title = $request->input('video_title'); $manage_free_video->video_description = $request->input('video_description'); $manage_free_video->video_cover_image = $imageName; $manage_free_video->video_url = $request->input('video_url'); $manage_free_video->save(); return $manage_free_video; } public function view_manage_video() { $manage_free_video = ManageFreeVideo::all()->toArray(); return $manage_free_video; } public function edit_manage_video($id) { $manage_free_video = ManageFreeVideo::find($id); return $manage_free_video; } public function update_mange_video(Request $request) { $manage_free_video = $request->edit_manage_video_id; $manage_free_video = ManageFreeVideo::find($request->edit_manage_video_id); if($request->hasFile('video_cover_image')){ $folderPath = public_path('/uploads/'); // dd($folderPath); File::delete($folderPath.$manage_free_video->video_cover_image); $image_parts = explode(";base64,", $request->img_path_edit); $image_type_aux = explode("image/", $image_parts[0]); $image_type = $image_type_aux[0]; $image_base64 = base64_decode($image_parts[1]); $imageName = uniqid() . '.png'; $imageFullPath = $folderPath.$imageName; file_put_contents($imageFullPath, $image_base64); }else{ $imageName = $manage_free_video->video_cover_image; } // if($request->hasFile('video_cover_image')){ // $path = public_path().'/uploads/'; // File::delete($path.$manage_free_video->video_cover_image); // $file = $request->file('video_cover_image'); // $ext = $file->extension(); // $file_name = time().'.'.$ext; // $file-> move($path,$file_name); // }else{ // $file_name = $manage_free_video->video_cover_image; // } $manage_free_video->video_type = $request->input('video_type'); $manage_free_video->video_title = $request->input('video_title'); $manage_free_video->video_description = $request->input('video_description'); $manage_free_video->video_cover_image = $imageName; $manage_free_video->video_url = $request->input('video_url'); $manage_free_video->save(); return $manage_free_video; } }