Laravel API is not accepting JSON
request. If I request as form-data it works but if I post JSON
object in postman body then it does not receive the request data.
Route:
$router->group(['prefix' => 'imp'], function () use ($router) {
$router->group(['prefix' => 'lead'], function () use ($router) {
$router->post('/jardy', 'FeedController@jardy');
});
});
Controller:
public function jardy(Request $request)
{
$this->validate($request, [
'api_key' => 'required',
]);
$api_key = $request->input('api_key');
return $api_key;
}
JSON
Request:
Form data Request:
Why its not working in case of JSON
, content-type
is application/json
, Accept:*/*
???
$request->validate([ 'api_key' => 'required' ])
work? – apokryfos$this->validate($request, [ 'api_key' => 'required', ]);
. You have nissed$request
. – Imdad Ali->validate($request->all()
instead of->validate($request
– Dilip HiraparaRequest
object. It shows error when i modify like you are suggesting. @Dilip Hirapara – Imdad Alivalidate
method on$request
not on$this
– apokryfos