Support the ongoing development of Laravel.io →
posted 10 years ago
Requests
Last updated 1 year ago.
0

The wantsJson() method checks the Accept HTML header for the string application/json and returns true if it is set.

The isJson() method checks that the HTML header CONTENT_TYPE contains the string /json and returns true if it is found.

Both methods are found in vendor/laravel/framework/src/Illuminate/Http/Request.php

  1. The ajax method set the content type and the accept headers to json and in my experience that tends to be the default behavior (although not to be assumed.)

  2. Your PHPUnit Test hasn't set any headers and thus why wantsJson and isJson methods return false

  3. The fact that isJson returned true here is likely because its called after the CONTENT_TYPE has been set

I hope this helps.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

guzzilar guzzilar Joined 20 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.