<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
 use App\User;
 use Auth;
 


class LoginController extends Controller
{
	 
			
	 public function loginpost(Request $rec)
        {
          //dd($rec->all()); 
      $rec->validate(["roletype"=>"required","username"=>"required","password"=>"required"]);

     $data=$rec->all();
     if(Auth::attempt(['email'=>$data['username'],'password'=>$data['password'],'role'=>$data['roletype']]))
    {
	$user= Auth::User();
	//dd($user);
	//echo $user->role;die;
	//dd($user->role);
	if($user->role=='superviser')
	{
     
     return redirect('dashboard');

	}else if($user->role=='labour')
	{
      return redirect('dashboard');

	}else{
		return redirect('dashboard');
	}

    //echo "<pre>";print_r($data1);


}else{
//ddd("not login");
	return redirect('/')->with('error','Invalid User Details !!');
}

          //echo "<pre>";print_r($data);
 }


public function logout(Request $request) {
  Auth::logout();
  return redirect('/');
}

     

}
