<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Admin;
use App\Models\TempQueueManagement;
use Session;
class RestoController extends Controller
{
    function index(){
        return view('login');
    }

    function dashboard(){
        $UserId = 19;
        $CurrDate = date('Y-m-d');
        TempQueueManagement::where('InDate','<',$CurrDate)->delete();
        $result = Admin::select()->where(['id'=>$UserId])->get();
        return view('dashboard',['UserData'=>$result]);
    }

    function login(Request $req){
       // return Admin::all();
       $Username = $req->Username;
       $Password = $req->Password;
       $result = Admin::select('id','Username','Password','Type','Name')->where(['Username'=>$Username,'Password'=>$Password])->get();
       $rowcnt = $result->count(); 
       if($rowcnt>0){
            $req->session()->put('UserId',$result[0]->id);
            $req->session()->put('UserType',$result[0]->Type);
            $req->session()->put('User_Name',$result[0]->Name);
            //return 19;
            //return redirect('/dashboard');
            return 1;
        }
        else{
            if(session()->has('UserId')){
                session()->pull('UserId');
            }
            return "Invalid Username & Password";
        }
    }
}
