<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class StateController extends Controller
{
    
    
    public function index()
    {
        //return view('home');
    }

    public function clearCache()
    {
        \Artisan::call('cache:clear');
        return view('clear-cache');
    }
    
    public function insertstate(Request $request)
    { 
        
        $state_code = $request->input('state_code');
        $state_name = $request->input('state_name');
        $status = $request->input('status');
        
        $data=array(
                "state_code"=>$state_code,
                "state_name"=>$state_name,
                "status"=>$status);
        
        $insdata = DB::table('state_master')->insert($data);
        return redirect('state-master-data');
    }
    public function getstate(Request $request)
    { 
        $getdata = DB::table('state_master')->get();
        // return View::make("state-master-data")->with('getdata',$getdata);
        return view('pages.state-master-data', compact('getdata'));
    }
    
    public function deletestate($id)
    { 
        $getdata = DB::table('state_master')->delete($id);
        return redirect('state-master-data');
    }
    
    public function showstate($id)
    {  
         $showdata = DB::table('state_master')->where('id','=',$id)->get();
         return view('pages.state-master', compact('showdata'));
        //  return view('pages.stateupdate-data', compact('showdata'));
    }
     public function updatestate(Request $request)
    { 
        
        $state_code = $request->input('state_code');
        $state_name = $request->input('state_name');
        $status = $request->input('status');
        $state_id = $request->input('id');
        
        $data=array(
                "state_code"=>$state_code,
                "status"=>$status,
                "state_name"=>$state_name);
        
        $insdata = DB::table('state_master')->where('id',$state_id)->update($data);
        return redirect('state-master-data');
    }
}
