<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Service;

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

    /**
     * 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, [
            'title'=>'required',
            'image' => 'required',
          
            'description' => 'required',
        ]);
        $save= new Service;
        $save->service_type=$request->service_type;
        $save->title=$request->title;
        $save->title_nepali=$request->title_nepali;
        $save->interest= $request->interest;
        $save->description=$request->description;
        $save->description_nepali=$request->description_nepali;
        $save->feature=$request->feature;
        $save->feature_nepali=$request->feature_nepali;
        $save->token=AdminlogController::getToken('Service');
        $save->save();
        AdminlogController::FileSaver( $request,'Service',1920,1285);
       return redirect('admin_service')->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=Service::where('id',$id)->first();
         $new_count=0;
         $new_count=AdminlogController::FileUpdater($request,'Service',1920,1285,null,$last->token);

        $data=array(

            'service_type'=>$request->service_type,

        'title'=>$request->title,
        'interest'=>$request->interest,
        'description'=>$request->description,
        'feature'=>$request->feature,


        'title_nepali'=>$request->title_nepali,
        'description_nepali'=>$request->description_nepali,
        'feature_nepali'=>$request->feature_nepali,
        
          
);


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

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