我正在尝试在我的控制器中将两个日期从一个视图传递到另一个视图,但是我收到以下错误: 传递给App \ Http \ Controllers \ GuestController :: reservationToGuest()的参数2必须是Illuminate \ Http \ Request的实例,没有给出
这是我的第一个视图(具有日期的视图):
case Nil => List.empty
(dateOne和dateTwo是我想要在第二个视图中的日期)
routes.php文件
<form action="{{ route('create_guest') }}">
{{ csrf_field() }}
<input type="hidden" value="2016-08-26" name="dateOne">
<input type="hidden" value="2016-08-28" name="dateTwo">
<button class="btn btn-block btn-success">Proceed To Check In</button>
</form>
GuestController中的reservationToGuest
Route::get('/guest_page/create/{idreservation?}',[
'uses' => 'GuestController@reservationToGuest',
'as' => 'create_guest'
]);
并在视图'guest_page_create'
public function reservationToGuest($idreservation = null, Request $request){
if($idreservation === null){
return view('guest_page_create', ['idreservation' => 0, 'page_title' => 'Guest Check In', 'check_in_date' => $request['dateOne']]);
} else{ //else clause works just fine and the dates from the database are inserted into the view
$details = DB::table('reservation')
->where('idreservation', $idreservation)
->get();
return view('guest_page_create', ['idreservation' => $idreservation, 'details' => $details, 'page_title' => 'Guest Check In']);
}
}
答案 0 :(得分:4)
在所需参数之前,您不应该传递可选参数。试试这个:
public function reservationToGuest(Request $request, $idreservation = null)
{
// ...
}