Wednesday, March 29, 2017

Laravel Multiple Optional Parameter Not Working and Two Back Slashes in URL

This is my route:

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";

}

Here, c_in & c_out are optional parameters.If I submit only c_out then URL shows like this: http://127.0.0.1:8000/edit_atten/31/2017-03-20//12:25:30 it creates routes problems. Because two slashes (//) shows in the URL! Though this (c_in) parameter is optional, why showing this?

Any solution for these ?



via Abhijit M. Abhi

Advertisement