<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Testimonial;

class TestimonialController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex()
    {
        return view('Admin.Testimonial');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'full_name'=>'required',
            'image' => 'required',
            'description' => 'required',
        ]);
        $save= new Testimonial;
        $save->full_name=ucwords($request->full_name);
        $save->full_name_nepali=$request->full_name_nepali;
        $save->post= $request->status;
        $save->post_nepali= $request->status_nepali;
        $save->description=$request->description;
        $save->description_nepali=$request->description_nepali;
        $save->token=AdminlogController::getToken('Testimonial');
        $save->save();
        AdminlogController::FileSaver( $request,'Testimonial',253,322);
       return redirect('admin_testimonial')->with('info', 'Datas Saved Successfully!');
    }

    /**
     * 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)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
         $last=Testimonial::where('id',$id)->first();
         $new_count=0;
         $new_count=AdminlogController::FileUpdater($request,'Testimonial',253,322,null,$last->token);

        $data=array(

        'full_name'=>$request->full_name,
        'full_name_nepali'=>$request->full_name_nepali,
        'description'=>$request->description,
        'description_nepali'=>$request->description_nepali,
        'post'=>$request->status,
        'post_nepali'=>$request->status_nepali,
      
       
        
          
);


        Testimonial::where('id',$id)->update($data);
        return redirect('admin_testimonial')->with('info', 'Data updated Successfully!');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
