관리-도구
편집 파일: TestimonialsController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Testimonial; class TestimonialsController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $data = Testimonial::where('is_active',1)->simplePaginate(9); return view('backend.testimonials.index',['data'=>$data]); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create(Request $request) { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $data=$request->except('_token'); if($request->hasFile('image')){ foreach($request->file('image') as $image) { $name=$image->getClientOriginalName(); $image->move(public_path().'/theme/default/images/', $name); $img[] = $name; } $data['image'] = json_encode($img); } $save = Testimonial::create($data); if($save){ return redirect(route('testimonialscms'))->with("success", "Testimonial has been created Successfully"); }else{ return redirect(route('testimonialscms'))->with("error","Sorry! Testimonial couldn't be created!"); } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $productsData = Testimonial::all()->where('id',(int)$id); $singleData= ''; foreach($productsData as $sData) { $singleData = $sData; } return view('backend.testimonials.show',['singleData'=>$singleData,'id'=>$id]); } public function showCreateForm() { return view('backend.testimonials.createform'); } public function getTestimonials() { $Testimonials = Testimonial::where('is_active',1)->get(); return $Testimonials; } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request) { $data=$request->all(); $result=Testimonial::find($request->id); if($request->hasFile('image')){ foreach($request->file('image') as $image) { $name=$image->getClientOriginalName(); $image->move(public_path().'/theme/default/images/', $name); $img[] = $name; } $data['image'] = json_encode($img); } $save=$result->fill($data)->save(); if($save){ return redirect(route('testimonialscms'))->with("success",'Data Updated Succesfully'); }else{ return redirect(route('testimonialscms'))->with("error",'Error Ocuured Data is not Updated!'); } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $result = Testimonial::where('id',$id)->delete(); if($result){ return redirect(route('testimonialscms'))->with("success",'Testimonial Removed Succesfully'); }else{ return redirect(route('testimonialscms'))->with("error",'Error Ocuured Testimonial is not Removed!'); } } }