middleware('auth'); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $page = "Testimonials List"; $testList = Testimonials::orderBy('id', 'DESC')->get(); return view("admin.testimonial.index", compact('testList','page')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $page = "Create New Testimonials"; return view("admin.testimonial.add", compact('page')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $testimonial = new Testimonials(); $input = $request->input(); $validator = Validator::make($input, [ 'username' => 'required', 'user_role' => 'required', 'description' => 'required', ], [ 'username.required' => 'User Name is required field.', 'user_role.required' => 'User Role is required field.', 'description.required' => 'Description is required field.', ]); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); } $testimonial->username = $request->username; $testimonial->user_role = $request->user_role; $testimonial->description = $request->description; if ($request->hasfile('user_pic')) { $image = $request->file('user_pic'); $destinationPath = "testimonialImage"; $uploadImage = Helper::imageResize(55,55, $image,$destinationPath); $testimonial->user_pic = $uploadImage; } $testimonial->save(); return Redirect::to("admin/testimonial")->with("success","Testimonials added successfully"); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $page = "View Testimonials Detail"; $testimonial = Testimonials::find($id); if($testimonial){ return view('admin.testimonial.view', compact('testimonial','page')); } else{ return Redirect::back()->with("danger","Something went wrong please try again"); } } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $page = "Edit Testimonials"; $testimonial = Testimonials::find($id); if($testimonial){ return view('admin.testimonial.edit', compact('testimonial','page')); } else{ return Redirect::back()->with("danger","Something went wrong please try again"); } } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $testimonial = Testimonials::find($id); $this->validate($request, [ 'username' => 'required', 'user_role' => 'required', 'description' => 'required', ], [ 'username.required' => 'User Name is required field.', 'user_role.required' => 'User Role is required field.', 'description.required' => 'Description is required field.', ]); $testimonial->username = $request->username; $testimonial->user_role = $request->user_role; $testimonial->description = $request->description; if(!empty($request->file('user_pic'))){ $image = $request->file('user_pic'); $ext = strtoupper($image->getClientOriginalExtension()); if($ext == "JPG" || $ext == "JPEG" || $ext == "PNG" || $ext == "GIF"){ $cat = Testimonials::getById($id); $destinationPath = "testimonialImage"; $unlinkImagePath = $cat->user_pic; $uploadImage = Helper::imageResize(55,55, $image,$destinationPath,$unlinkImagePath); $testimonial->user_pic = $uploadImage; } else{ return Redirect::back()->with("danger","Please select jpg, png, gif only"); } } $testimonial->save(); return Redirect::to("admin/testimonial")->with("success","Testimonials updated successfully"); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $testimonial = Testimonials::where('id',$id)->first(); $filename = public_path('/uploads/testimonialImage/'.$testimonial->user_pic); if(file_exists($filename) && !empty($testimonial->user_pic)){ unlink($filename); } $filename1 = public_path('/uploads/testimonialImage/thumbnail/'.$testimonial->user_pic); if(file_exists($filename1) && !empty($testimonial->user_pic)){ unlink($filename1); } $result = Testimonials::where('id',$id)->forceDelete(); if($result){ return Redirect::back()->with("success","Testimonials deleted successfully"); } else{ return Redirect::back()->with("danger","Something went wrong please try again"); } } }