我正在尝试将用户登录并将其带到显示基于slug的内容的页面。
我收到此错误:
ErrorException in ApplicantLoginController.php line 21:
Missing argument 2 for App\Http\Controllers\Auth\ApplicantLoginController::Login()
这是我的控制者:
public function Login(Request $request, $slug){
//Validate the form
$this->validate($request, [
'email' => 'required',
'password' => 'required',
'agree' => 'required'
]);
//Attempt to log the user in
if (Auth::guard('applicant')->attempt(['email' => $request->email,'password' => $request->password] )) {
$house = House::where('slug', '=', $slug)->first();
return view('client.index')->withHouse($house);
}
return redirect()->back()->withInput($request->only('email'));
}
这是登录后我带他们去的页面的路线:
Route::get('client/index/{slug}', ['as' => 'client.index', 'uses' => 'ClientRegistrationController@index']);
这是我的登录路线:
Route::get('client/login', 'Auth\ApplicantLoginController@ShowLoginForm')->name('client.login');
Route::post('/client/login', 'Auth\ApplicantLoginController@Login')->name('client.login.submit');
关于如何解决这个问题的任何想法?
这个按钮将用户带到页面,内容基于slug
<a href="{{ url('client/index/'.$house->slug) }}" class="btn btn-success btn btn-block">Book now</a>
如果用户未登录页面,则会重定向到此登录页面:
<form class="form-horizontal" role="form" method="POST" action="{{ route('client.login.submit') }}">
<input name="_token" type="hidden" value="{{ csrf_token()}}"/>
<div class="form-group">
<label for="email" class="col-md-3 control-label"></label>
<div class="col-md-6">
<input type="email" class="form-control" placeholder="Your Email" name="email" required="">
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-3 control-label"></label>
<div class="col-md-6">
<input type="password" class="form-control" placeholder="Password" name="password" required="">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<div class="checkbox">
<label>
<input type="checkbox" name="remember"> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<div class="checkbox">
<label>
<input type="checkbox" name="agree" required=""> I have read and accepted the <a href="" data-toggle="modal" data-target="#myModal" class="checkbox-terms-client">terms and condition</a>
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-3">
<input type="submit" value="Login" class="btn btn-primary">
</input>
<a class="btn btn-link" href="#">
Forgot Your Password?
</a>
</div>
</div>
</form>
答案 0 :(得分:0)
您应该在邮寄路线中声明$ slug:
Route::post('/client/login/{slug}', 'Auth\ApplicantLoginController@Login')->name('client.login.submit');
并更改表单以添加参数:
<form class="form-horizontal" role="form" method="POST" action="{{ route('client.login.submit', ['slug' => $slug]) }}">