<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\modelLogin;
use Illuminate\Support\Facades\Session;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redirect;
class loginController extends Controller
{
   
    public function login(Request $request)
    {
       // Validate the request data
            $request->validate([
                'username' => 'required|string',
                'password' => 'required|string',
            ]);
    
            $username = $request->input('username');
            $password = $request->input('password');
    
            $result = modelLogin::loginuser($username, $password);
            if (count($result) > 0 ) {
                
               // return redirect()->intended('/Landing');
               $user = $result[0];
               Session::put('Name', $user->FullName);
               Session::put('RegNo', $user->UserCode);
               //$properties = modelProperty::selectProperty(Session::get('RegNo'));
               return redirect()->route(route: 'landing');
              // return view('/Landing', compact('properties'));
             

            } 
            else 
            {
              
                return redirect()->back()->withErrors(['username' => 'Invalid credentials.']);
            }
        
        }
}
