{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/9391","labels_url":"https://api.github.com/repos/laravel/framework/issues/9391/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/9391/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/9391/events","html_url":"https://github.com/laravel/framework/pull/9391","id":90447636,"number":9391,"title":"[5.1] Add Request::wants()","user":{"login":"crynobone","id":172966,"avatar_url":"https://avatars.githubusercontent.com/u/172966?v=3","gravatar_id":"","url":"https://api.github.com/users/crynobone","html_url":"https://github.com/crynobone","followers_url":"https://api.github.com/users/crynobone/followers","following_url":"https://api.github.com/users/crynobone/following{/other_user}","gists_url":"https://api.github.com/users/crynobone/gists{/gist_id}","starred_url":"https://api.github.com/users/crynobone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crynobone/subscriptions","organizations_url":"https://api.github.com/users/crynobone/orgs","repos_url":"https://api.github.com/users/crynobone/repos","events_url":"https://api.github.com/users/crynobone/events{/privacy}","received_events_url":"https://api.github.com/users/crynobone/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-06-23T17:42:04Z","updated_at":"2015-06-26T01:06:48Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/9391","html_url":"https://github.com/laravel/framework/pull/9391","diff_url":"https://github.com/laravel/framework/pull/9391.diff","patch_url":"https://github.com/laravel/framework/pull/9391.patch"},"body":"Determines whether the current requests accepts a given content type based on content negotiation.\r\n\r\nAs of now, client (browser/API) can provide a list of `Accept` content-type that it can handle (with content-negotiation), however there no way for the server (Laravel) to choose the most suitable response content-type that it can support.\r\n\r\n### Current Behaviour\r\n\r\n```php\r\nif ($request->wantsJson()) {\r\n   return $user->toJson();\r\n} elseif ($request->accepts('text/html')) {\r\n   return view('users', compact('users');\r\n}\r\n```\r\n\r\nThis is based on the assumption that we going to return json if it can accept it, regardless if json has `q=0.5` and html has `q=0.8` as an example.\r\n\r\n### Expected Behaviour\r\n\r\n```php\r\nswitch ($request->wants(['html', 'json', 'xml'])) {\r\n   case 'json' :\r\n      return $user->toJson();\r\n   case 'html':\r\n      return view('users', compact('users');\r\n   case 'xml':\r\n      // return xml\r\n   default:\r\n      // maybe throw an exception.\r\n}\r\n```\r\n\r\nReplace #9346\r\n\r\nSigned-off-by: crynobone <crynobone@gmail.com>"},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/115450270","html_url":"https://github.com/laravel/framework/pull/9391#issuecomment-115450270","issue_url":"https://api.github.com/repos/laravel/framework/issues/9391","id":115450270,"user":{"login":"taylorotwell","id":463230,"avatar_url":"https://avatars.githubusercontent.com/u/463230?v=3","gravatar_id":"","url":"https://api.github.com/users/taylorotwell","html_url":"https://github.com/taylorotwell","followers_url":"https://api.github.com/users/taylorotwell/followers","following_url":"https://api.github.com/users/taylorotwell/following{/other_user}","gists_url":"https://api.github.com/users/taylorotwell/gists{/gist_id}","starred_url":"https://api.github.com/users/taylorotwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taylorotwell/subscriptions","organizations_url":"https://api.github.com/users/taylorotwell/orgs","repos_url":"https://api.github.com/users/taylorotwell/repos","events_url":"https://api.github.com/users/taylorotwell/events{/privacy}","received_events_url":"https://api.github.com/users/taylorotwell/received_events","type":"User","site_admin":false},"created_at":"2015-06-26T01:06:48Z","updated_at":"2015-06-26T01:06:48Z","body":"`wants` seems like a strange method name since it returns a string. I would expect `wants` to return a bool? Like \"do you want this?\"....\r\n\r\nIs there a better method name we can come up with? Maybe `prefers`? Just thinking out loud..."}}