这是我的路线:
Route::get('/edit_atten/{id}/{date}/{c_in?}/{c_out?}', 'AttendanceController@editAttendance');
http://127.0.0.1:8000/edit_atten/31/2017-03-20//12:25:30
public function editAttendance($id, $date, $c_in=null, $c_out=null)
{
$this_user = Attendance::find($id);
$this_user->check_in = $c_in;
$this_user->check_out = $c_out;
$this_user->save();
echo "Success";
}
在这里, c_in & c_out 是可选参数。如果我只提交 c_out ,则网址会显示如下:http://127.0.0.1:8000/edit_atten/31/2017-03-20//12:25:30它会产生路线问题。因为URL中显示了两个斜杠(//)!虽然这个( c_in )参数是可选的,为什么要显示这个?
这些解决方案?
答案 0 :(得分:2)
Route::get('/edit_atten', 'AttendanceController@editAttendance');
http://127.0.0.1:8000/edit_atten?id=31&date2017-03-20&c_out=12:25:30
public function editAttendance(Request $request)
{
$id = $request->input('id');
$date = $request->input('date');
$c_in = $request->input('c_in');
$c_out = $request->input('c_out');
$this_user = Attendance::find($id);
$this_user->check_in = $c_in;
$this_user->check_out = $c_out;
$this_user->save();
echo "Success";
}