<?php

namespace App\Http\Controllers;

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

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

    public function clearCache()
    {
        \Artisan::call('cache:clear');
        return view('clear-cache');
    }
    
    public function insertuserlogin(Request $request)
    { 
        $useremail = $request->input('email');
        $userpass = Hash::make($request->input('userpass'));
        $username = $request->input('name');
        $state_code = $request->input('state_code');
        $dist_code = $request->input('dist_code');
        
        $data=array(
                "state_code"=>$state_code,
                "dist_code"=>$dist_code,
                "name"=>$username,
                "email"=>$useremail,
                "password"=>$userpass);
        
        $insdata = DB::table('users')->insert($data);
        return redirect('user-login-data');
    }
    
    public function getuserlogin(Request $request)
    { 
        $getdata = DB::table('users')->get();
        return view('pages.user-login-data', compact('getdata'));
    }
    
    public function deleteuserlogin($id)
    { 
        $getdata = DB::table('users')->delete($id);
        return redirect('user-login-data');
    }
    
    public function showuserlogin($id)
    {  
         $showdata = DB::table('users')->where('id','=',$id)->get();
         return view('pages.user-login', compact('showdata'));
    }
    
    public function updateuserlogin(Request $request)
    { 
        
        $user_id = $request->input('userid');
        $dist_code = $request->input('dist_code');
        $state_code = $request->input('state_code');
        $username = $request->input('name');
        $useremail = $request->input('email');
        
        $data=array(
                "state_code"=>$state_code,
                "dist_code"=>$dist_code,
                "name"=>$username,
                "email"=>$useremail);
                
        $insdata = DB::table('users')->where('id',$user_id)->update($data);
        return redirect('user-login-data');
    }
    
    
    
    
}
