<?php

namespace App\Http\Controllers;

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

class UserController extends Controller
{
    //
    public function login_index()
    {
        return view('login',['title'=>'登入後使用 測試用 帳(密) test(test)']);
    }


    public function login(Request $request)
    {
        $login_user=User::where('name',$request->username)->where('password',$request->password)->first();
//        return $login_user;

//        printf($login_user);
        if($login_user !==null){
            Auth::loginUsingId($login_user->id);
            return redirect('index');
        }

        return view('login',['title'=>'登入後使用','msg'=>'帳號或密碼錯誤']);
    }

    public function logout()
    {
        Auth::logout();
        return redirect('/log_in');
    }


    public function insert(Request $request)
    {
//
    }


}

