vendredi 11 mars 2016

How to pass Accept: application json header in call, post request Laravel 5.1

How do I pass the "Accept: application/json" in request when testing:

for eg:

$response = $this->post($route, $data, ['Accept: application/json']);

OR

$response = $this->call('post' $route, $data, [], [], ['Accept: application/json']);

I want to invoke $this->wantsJson() in the FormRequest class:

/**
     * 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);
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire