<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Session; 

class LoginController extends Controller
{
    //

    public function signin_process(Request $request) {

        $signin_email=$request->input('username');
        
        $signin_password=$request->input('password');
        
        
        $signin_details = DB::table('admin')
                                ->where('user_name',$signin_email)
                                ->count();
    

        if($signin_details == '1')
        {
            $signin_details=DB::table('admin')
            ->where('user_name', $signin_email)
            ->get();

            foreach($signin_details as $value) 
            {
                $db_pass = $value->password;
                $userid = $value->id;
            }
            if($signin_password == $db_pass)
            {
                Session::put('admin_userid',$userid);
                return redirect('dashboard');
            }
            else
            {
                return redirect('admin')->with('error', 'Invalid Login Credentials');
            }

        } else {

            return redirect('admin')->with('error', 'Invalid Login Credentials');
        }        
    }
}
