我想創建簡單的登入系統,並且我製作了一個登入系統,但它說登入詳細資訊錯誤。我嘗試做轉儲測試回傳 null。請參閱評論中的 dd 測試。由於這個原因也無法註銷
我的登入控制器是:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use App\Models\User; use Validator; class LoginController extends Controller { public function index() { return view('login'); } public function store(Request $request) { $this->validate($request, [ 'email' => 'required|email', 'password' => 'required|alphaNum|min:3' ]); $user_data = array( 'email' => $request->get('email'), 'password' => $request->get('password') ); //$user = Auth::user(); //dd($user); I have done dump test but it is returning null if(Auth::attempt($user_data)) { return redirect()->route('welcome'); } else { return back()->with('error','wrong Login Details'); } } }
我的登入刀片是
@if ($message = Session::get('error')) <div class="alert alert-danger alert-block"> <button type="button" class="close" data-dismiss="alert">×</button> <strong>{{ $message }}</strong> </div> @endif @if (count($errors) > 0) <div class="alert alert-danger"> <ul> @foreach($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @萬一
網路路由是
Route::get('/register','App\Http\Controllers\RegisterController@index')->name('register'); 路線::post('/register/save','App\Http\Controllers\RegisterController@store')->name('register.save'); 路線::get('/login','App\Http\Controllers\LoginController@index')->name('login'); 路線::post('/login/save','App\Http\Controllers\LoginController@store')->name('login.save'); 路線::get('/welcome','App\Http\Controllers\LogoutController@store')->name('logout');
嘗試偵錯您的程式碼
1- 註冊後查看資料庫。您的密碼是否已加密?
2-提交表單時 dd($request->all()) 如果一切順利的話
3- Auth::attempt($request->only('電子郵件', '密碼'))
我希望這個答案可以幫助您調試程式碼。