2

I am using a route with 2 optional parameters and I would like that either one of them can be chosen because they are used in a where clause. The where clause can be used on the first parameter OR the second one.

I tried this:

Route::get('activityperemployee/employee_id/{employee_id?}/month/{month?}', ['uses'=>'Ajax\ActivityAjaxController@getActivityPerEmployee','as'=>'ajaxactivityperemployee']);

but the problem is I can't find the page anymore if I don't set up both of the parameters.

Richard
  • 703
  • 3
  • 11
  • 33

2 Answers2

1

The problem is the first parameter {employee_id?}. You cannot use it in this way becasue if You won't pass any params You'll get url like:

activityperemployee/employee_id//month

which won't find your route.

I think You should make required at least {employee_id} (without question mark) and always passing first parameter.

Filip Koblański
  • 9,718
  • 4
  • 31
  • 36
1

I suggest to use a get variable.

If you have multiple optional parameters

Route::get('test',array('as'=>'test','uses'=>'HomeController@index'));

And inside your Controller

class HomeController extends BaseController {
    public function index()
    {
        // for example /test/?employee_id=1&month=2
        if(Input::has('id'))
        echo Input::get('id'); // print 1
        if(Input::has('page'))
        echo Input::get('page'); // print 2
        //...
    }
}

Hope this works for you! More information at https://stackoverflow.com/a/23628839/2859139

Community
  • 1
  • 1
Robin Dirksen
  • 3,322
  • 25
  • 40