<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\About;
use DB;
class AboutController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex()
{       $about=About::first();
        return view('Admin.About')->with('aa', $about);
    }

    /**
     * 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)
    {
        $users = DB::table('abouts')->count();
            if($users==0){
            $new=new About;
            $new->introduction=$request->introduction;
            $new->introduction_nepali=$request->introduction_nepali;
            $new->mission=$request->mission;
            $new->mission_nepali=$request->mission_nepali;
            $new->vision=$request->vision;
            $new->vision_nepali=$request->vision_nepali;
            $new->objective=$request->objective;
            $new->objective_nepali=$request->objective_nepali;
            $new->saving_nepali=$request->saving_nepali;
             $new->saving=$request->saving;
            $new->loan_nepali=$request->loan_nepali;
             $new->loan=$request->loan;
            $new->remittance_nepali=$request->remittance_nepali;
             $new->remittance=$request->remittance;
            
            $new->token=AdminlogController::getToken('About');
            $new->save();
            // AdminlogController::FileSaver( $request,'About',1920,1285);
        }else{

             $last=About::where('id','=',1)->first();
            // $new_count=0;
            // $new_count=AdminlogController::FileUpdater($request,'About',1920,1285,null,$last->token);
              $data = array(
              
                'introduction' => $request->input('introduction'),
                'introduction_nepali' => $request->input('introduction_nepali'),
                'mission' => $request->input('mission'),
                'mission_nepali' => $request->input('mission_nepali'),
                'vision' => $request->input('vision'),
                'vision_nepali' => $request->input('vision_nepali'),
                'objective' => $request->input('objective'),
                'objective_nepali' => $request->input('objective_nepali'),
                'saving' => $request->input('saving'),
                'saving_nepali' => $request->input('saving_nepali'),
                'loan' => $request->input('loan'),
                'loan_nepali' => $request->input('loan_nepali'),
                'remittance' => $request->input('remittance'),
                'remittance_nepali' => $request->input('remittance_nepali'),
               
                
               
            );

          About::where('id','=',1)->update($data);

        }


          
          return redirect('admin_about')->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)
    {
        //
    }

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