<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use DB;
use Illuminate\Support\Facades\Session;    
class SelectController extends Controller {


    public function select(Request $request){

        $ac = $request->input('account');
        $pw = $request->input('passwordinput');

        // $user = ivy::where('id','>','10')
        //     ->where(function($q1) use($pid,$uid){
        //         $q1->orWhere('pid',$pid)
        //         ->orWhere('uid',$uid);
        //     })->get();

        $email = DB::table('ivy')->where('account', $ac)->where('password',$pw)->get();
        if($email->first()){ 
            Session::put('ac', $ac);
            echo "<script>alert('登入成功');parent.location.href='/';</script> ";
        }
        else {

            echo "<script>alert('帳號密碼錯誤');parent.location.href='/'</script> ";

        }

    }
    
    public function authenticate(Request $request)
    {
        $ac = $request->input('account');
        $pw = $request->input('passwordinput');
        if (Auth::attempt(['name' => $ac, 'password' => $pw])) {
            // 如果認證通過...
            // return redirect()->intended('page');
            return 'yy';
        }
        else{
            return 'no';
        }
    }
}