laravel - get parameters from http request laravel - get parameters from http request angularjs angularjs

laravel - get parameters from http request


Change this:

$router->get('/api/questions/check/(:any)', 'ApiController@getAnswer');

to

$router->get('/api/questions/check', 'ApiController@getAnswer');

And fetch the values with

echo $request->id;echo $request->choices;

in your controller. There is no need to specify that you will receive parameters, they will all be in $request when you inject Request to your method.


Update for Laravel 8:

Sometimes you may want to pass in parameters without using query strings.

EX

Route::get('/accounts/{accountId}', [AccountsController::class, 'showById'])

In your controllers method, you can use a Request instance and access the parameters like so using the route method:

public function showById (Request $request){  $account_id = $request->route('accountId')    //more logic here}

But if you still wanted to use some query params then you can use that same Request instance and just use the query method

Endpoint: https://yoururl.com/foo?accountId=4490
 public function showById (Request $request){  $account_id = $request->query('accountId');    //more logic here}