Sang Trần
Sang Trần

Reputation: 2307

Laravel PUT request parameter

When the route is:

  Route::post('/abcd',...); 

Then in controller I get the parameter like this:

   $r->get('param')   // with Request $r

But while the route is of a PUT request type:

   Route::put('/abcd,...);

That code doesn't work. It doesn't get the value of parameter.

Upvotes: 11

Views: 32250

Answers (5)

Arthur
Arthur

Reputation: 2889

Try setting x-www-form-urlencoded for body in the postman.

Upvotes: 37

Random5000
Random5000

Reputation: 1660

If submitting an API request and you don't want your developers to send a POST request with _method=PUT request variable, see solution here: https://github.com/laravel/framework/issues/13457#issuecomment-341973180

Upvotes: 2

Awais Jameel
Awais Jameel

Reputation: 2206

<input type="hidden" name="_method" value="PUT">

Just added an extra field in form. works perfect!

Upvotes: 3

Khesayed
Khesayed

Reputation: 362

Set method to POST and add _method field with PUT valueenter image description here

Upvotes: 15

mshakeel
mshakeel

Reputation: 612

Route:

$api->put('photos', 'App\Api\V1\Controllers\PhotoController@updatePhoto');

Controller code:

public function updatePhoto(Request $request)
{
    $paramValue = $request->get('param_name');
}

Working fine for me.

Upvotes: 3

Related Questions