/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(ArticleRequest $request, $id) { $article = Article::findOrFail($id); //get the current files $oldFile = $article->image; $oldThumb = $article->thumbimage; $article->title = $request->title; $article->body = $request->body; if ($request->file('image')) { //client has uploaded a new file $article->image = $request->file('image')->getClientOriginalName(); File::delete(base_path() . '/public/images/article/' . $oldFile); //delete the old image //move uploaded file to article dir $request->file('image')->move(base_path() . '/public/images/article/', $request->file('image')->getClientOriginalName()); } if ($request->file('thumbimage')) { //client has uploaded a new file $article->thumbimage = $request->file('thumbimage')->getClientOriginalName(); File::delete(base_path() . '/public/images/article/thumb/' . $oldThumb); //delete the old image //move uploaded file to article dir $request->file('thumbimage')->move(base_path() . '/public/images/article/thumb/', $request->file('thumbimage')->getClientOriginalName()); } $article->update(); return redirect('articles'); }
/** * Display a listing of the resource. * * @return Response */ public function index() { //load the home page of all models for resume entry $educations = Education::orderBy('graduationyear', 'desc')->get(); $skillcategories = SkillCategory::orderBy('title', 'asc')->get(); $jobs = Job::orderBy('currentlyemployed', 'desc')->orderBy('enddate', 'desc')->get(); $article = Article::findOrFail('1'); //get the summary article with id of 1 return view('admin.index', compact('educations', 'jobs', 'skillcategories', 'article')); }