public function postAddPaper() { if (\Auth::Check()) { $data = Input::all(); array_pop($data); $rules = ['subject' => 'required', 'year' => 'required', 'semester' => 'required']; $validator = Validator::make($data, $rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator->errors())->withInput(); } else { if (Input::hasFile('file')) { if (Input::file('file')->isValid()) { $destinationPath = 'papers'; // upload path $extension = Input::file('file')->getClientOriginalExtension(); // getting image extension if ($extension == 'pdf') { $fileName = $data['subject'] . '_' . $data['year'] . '_' . $data['semester'] . '.' . $extension; // renameing image Input::file('file')->move($destinationPath, $fileName); // uploading file to given path $paper = new Papers(); $paper->name = $fileName; $path->path = $destinationPath; $paper->save(); } } } Session::flash('err', "1"); return redirect('view_papers'); } } else { return redirect('login'); } }
public function getViewPapers() { $menu = Menu::Orderby('id', 'des')->get(); $papers = Papers::Orderby('id', 'des')->get(); $id = 1; if (\Auth::Check()) { $user = User::where('username', Session::get('username'))->first(); return view('papers')->with('papers', $papers)->with('id', $id)->with('username', $user->username)->with('level', $user->level)->with('menu', $menu); } else { return redirect('login'); } }