2
我如何通過 「接受:應用/ JSON的」 請求中的測試時:如何通過接受:應用JSON頭呼叫,POST請求Laravel 5.1
爲如:
$response = $this->post($route, $data, ['Accept: application/json']);
OR
$response = $this->call('post' $route, $data, [], [], ['Accept: application/json']);
我想在FormRequest類調用$this->wantsJson()
:
/**
* Get the proper failed validation response for the request.
*
* @param array $errors
* @return \Symfony\Component\HttpFoundation\Response
*/
public function response(array $errors)
{
if ($this->ajax() || $this->wantsJson()) {
return new JsonResponse($errors, 422);
}
return $this->redirector->to($this->getRedirectUrl())
->withInput($this->except($this->dontFlash))
->withErrors($errors, $this->errorBag);
}
是在5.1這個可用? –
我更新了我的答案。 –