Monday, April 15, 2013

Laravel Routes: Missing argument 1 for {closure}()

Problem:
While trying to develop quickly I set up a routing rule for Laravel that I thought was correct. But when I tried to access the page, I was met by this error:

Missing argument 1 for {closure}()

My Routing Rule looked like this:

Route::any('dashboard', array(     
    'before' => 'auth',     
    'as'     => 'base',      
    function($action){         
        return Controller::call("user@index");     
}));


Solution:
This was an oversight on my part, the closure used in the route expected an argument which would be the information obtained by any shortcuts [(:any),(:num),etc.] or regex rules. Since this particular route didn't have any captured portions of the URL, the closure also expected no arguments. My working route looks like this with the argument removed:
Route::any('dashboard', array(
    'before' => 'auth',
    'as'     => 'base', 
    function(){
        return Controller::call("user@index");
    }
));

No comments: