Three different methods in Laravel for if the request is asking for JSON. Are they the same? Do any overlap?

Viewed 2415

So these three methods are in the Laravel docs for testing if the request is for JSON.

I basically want to return JSON for any request that is requesting JSON or AJAX.

Request::ajax() Request::isJson() Request::wantsJson()

Can I use any of these? Do they overlap?

3 Answers
  1. request()->ajax() is usefull if you want to check if request is only Ajax

  2. Request::wantsJson() is usefull if you want to check if request is only Json

  3. Request::expectsJson() is usefull if you want to check if request is either Ajax or Wants Json

Related