public static function UploadFile($request) { $type = FileType::findOrFail($request->input('file_type_id')); $file = new File(); $filename = uniqid(); $newname = $request->input('newname'); if ($request->hasFile('file')) { if (isset($newname[0])) { $file->slug = str_replace(['/', '\\'], '', $newname); } else { $file->slug = $filename; } $file->filename = $filename; $file->file_ext = $request->file('file')->getClientOriginalExtension(); $file->path_to_file = 'uploads/files/'; if ($type->image) { $file->path_to_file = 'uploads/images/'; } $destinationPath = public_path($file->path_to_file); $request->file('file')->move($destinationPath, $filename . '.' . $file->file_ext); $file->path_to_file = '/' . $file->path_to_file; $file->file_type_id = $type->id; $file->fullname = $file->filename . '.' . $file->file_ext; $file->description = $request->input('description'); $file->alt_text = $request->input('alt_text'); $file->uploader = null; $file->path_to_file = $file->path_to_file . $file->fullname; $file->save(); return redirect()->action('FilesController@index'); } return back()->withErrors(['File not found. Please try again']); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $filecount = \App\Models\File::where('file_type_id', $id)->count(); if ($filecount > 0) { return back()->withMsg('There are files in the category'); } FileType::findOrFail($id)->delete(); return back(); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $types = FileType::all(); return view('admin.files.create', ['types' => $types]); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $types = FileType::where('image', 1)->get(); return view('admin.blog.posts.createPost', ['types' => $types]); }