Warning: Missing argument 1 when passing parameters from url to controller (laravel)

I am creating this site and I want to pass URL parameters to routes and routes to the controller, I searched for documents and Google, but I can not find a solution to my problem.

This is an example url

locations/search?q=parameter1

My route right now is as follows:

Route::group(array('prefix'=>'search'),function()
{
    Route::get('locations/{src?}','SearchController@locations',function($src = null){});
});

and my controller is as follows:

    class SearchController extends BaseController {

    public function locations($src)
    {
        return json_encode($src);
    }

}

I want to know how to pass the parameter to the controller, the code that I have now returns this error

{"error": {"type": "ErrorException", "message": "Missing argument 1 for SearchController :: locations ()", "file": "C: \ wamp \ www \ localsite \ app \ controllers \ SearchController .php "," line ": 5}}

Thank you in advance

+4
1

get . , - search/locations/search/, search $src

1
, , search/locations/parameter1, 1 $src

2
, locations/search/parameter1, :

Route::group(array('prefix'=>'locations'),function()
{
    Route::get('search/{src?}','SearchController@locations',
        function($src = null){
    });
});

locations/search/parameter1

get (location/search? q = parameter1).

3
:

Route::group(array('prefix'=>'locations'),function()
{
    Route::get('search','SearchController@locations');
});

:

class SearchController extends BaseController {

    public function locations()
    {
        $src = Input::get('q');
        return json_encode($src);
    }

}

$src , public function locations($src) = > public function locations($src = null)

+2

All Articles