Saya ingin mencipta sistem log masuk mudah dan saya telah membuatnya tetapi ia mengatakan butiran log masuk yang salah. Percubaan saya untuk melakukan ujian dump mengembalikan nol. Lihat ujian dd dalam komen. Atas sebab ini, saya tidak boleh log keluar
Pengawal log masuk saya ialah:
<?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'); } } }
Bilah log masuk saya ialah
@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>
Penghalaan rangkaian ialah
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');
Cuba nyahpepijat kod anda
1- Semak pangkalan data selepas pendaftaran. Adakah kata laluan anda disulitkan?
2-Apabila menyerahkan borang dd($request->all()) Jika semuanya berjalan lancar
3- Auth::attempt($request->only('email', 'password'))
Saya harap jawapan ini membantu anda nyahpepijat kod anda.