multiformat(); /** * Use `Request::match()` to return the right response for the requested format. * * Supports closures to avoid doing unnecessary work, and returns 404 if the * requested format is not supported. * * Will also take into account the `Accept` header if no extension is provided. */ class PodcastsController { public function show($id) { $podcast = Podcast::findOrFail($id); return request()->match([ 'html' => view('podcasts.show', [ 'podcast' => $podcast, 'episodes' => $podcast->recentEpisodes(5), ]), 'json' => $podcast, 'xml' => function () use ($podcast) { return response($podcast->toXml(), 200, ['Content-Type' => 'text/xml']); } ]); } }