当我发送请求时,它具有电子邮件和密码。但尝试无效
class AdminController extends Controller
{
public function login(Request $request)
{
//dd($request->email , $request->password);
if ($request->isMethod('post')){
if (Auth::attempt(['email'=>$request->email, 'password'=>$request->password, 'admin'=>'1'])){
echo 'success'; die();
}
else{
echo 'failed'; die();
}
}
return view('admin.admin_login');
}
}
当用户注册数据时,将这样存储:
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'university'=>$data['university'],
'grade'=>$data['grade'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
请帮助!
答案 0 :(得分:-1)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
/**
* Handle an authentication attempt.
*
* @param \Illuminate\Http\Request $request
*
* @return Response
*/
public function authenticate(Request $request)
{
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
// Authentication passed...
return redirect()->intended('dashboard');
}
}
}
这是来自Larvel document的示例。确保您的密码正确并且之前没有进行哈希处理。您也可以对用户名和密码进行硬编码,以确保数据正确无误。
答案 1 :(得分:-2)
您需要将$ request与输入配合使用,如以下代码所示。这是文档https://laravel.com/docs/5.6/requests#accessing-the-request
(Auth::attempt(['email'=>$request->input('email'), 'password'=>$request->input('password'), 'admin'=>'1']))