Ich möchte ein einfaches Anmeldesystem erstellen und habe eines erstellt, aber dort werden falsche Anmeldedaten angezeigt. Mein Versuch, einen Dump-Test durchzuführen, gibt null zurück. Siehe den dd-Test in den Kommentaren. Aus diesem Grund kann ich mich nicht abmelden
Mein Login-Controller ist:
<?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'); } } }
Mein Login-Blade ist
@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> @endif <form action="{{route('login.save')}}" style="border:1px solid #ccc" method="post"> {{ csrf_field() }} <div class="container"> <h1>Login</h1> <p>Please fill in this form to Login</p> <hr> <label for="email"><b>Email</b></label> <input type="text" placeholder="Enter Email" name="email" value="{{old('name')}}" > @error('email') {{$message}} @enderror <label for="psw"><b>Password</b></label> <input type="password" placeholder="Enter Password" name="password" > @error('password') {{$message}} @enderror <label for="psw-repeat"><b>Repeat Password</b></label> <input type="password" placeholder="Repeat Password" name="psw-repeat" > <div class="clearfix"> <button type="submit" class="signupbtn">Log in</button> </div> </div> </form> </body> </html>
Netzwerk-Routing ist
Route::get('/register','App\Http\Controllers\RegisterController@index')->name('register'); Route::post('/register/save','App\Http\Controllers\RegisterController@store')->name('register.save'); Route::get('/login','App\Http\Controllers\LoginController@index')->name('login'); Route::post('/login/save','App\Http\Controllers\LoginController@store')->name('login.save'); Route::get('/welcome','App\Http\Controllers\LogoutController@store')->name('logout');
尝试调试您的代码
1- 注册后查看数据库。您的密码是否已加密?
2-提交表单时 dd($request->all()) 如果一切顺利的话
3- Auth::attempt($request->only('电子邮件', '密码'))
我希望这个答案可以帮助您调试代码。