Skip to content

Instantly share code, notes, and snippets.

@localdisk
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save localdisk/73c67bf2558e202c4bc4 to your computer and use it in GitHub Desktop.

Select an option

Save localdisk/73c67bf2558e202c4bc4 to your computer and use it in GitHub Desktop.
CakePHP の Router::parseExtensions っぽい動きを Laravel で考えてみた
<?php
Route::get('api/members{ext?}', function($ext = null)
{
if (is_null($ext)) {
$ext = 'view';
}
$ext = ltrim($ext, '.');
// ここはちょっと考える必要あるかも
// View の切り替えをしたい場合は View::make がいいかもしれません
return Response::$ext('test');
// Response::xml を使う場合は https://gist.github.com/localdisk/8643113
// を参照してください
})->where('ext', '.xml|.json');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment