routes.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Application Routes
  5. |--------------------------------------------------------------------------
  6. |
  7. | Simply tell Laravel the HTTP verbs and URIs it should respond to. It is a
  8. | breeze to setup your application using Laravel's RESTful routing and it
  9. | is perfectly suited for building large applications and simple APIs.
  10. |
  11. | Let's respond to a simple GET request to http://example.com/hello:
  12. |
  13. | Route::get('hello', function()
  14. | {
  15. | return 'Hello World!';
  16. | });
  17. |
  18. | You can even respond to more than one URI:
  19. |
  20. | Route::post(array('hello', 'world'), function()
  21. | {
  22. | return 'Hello World!';
  23. | });
  24. |
  25. | It's easy to allow URI wildcards using (:num) or (:any):
  26. |
  27. | Route::put('hello/(:any)', function($name)
  28. | {
  29. | return "Welcome, $name.";
  30. | });
  31. |
  32. */
  33. Route::controller(Controller::detect());
  34. Route::get('/json', function()
  35. {
  36. return Response::json(array('message' => 'Hello, World!'));
  37. });
  38. Route::get('/db', function()
  39. {
  40. $queries = Input::get('queries', 1);
  41. $worlds = array();
  42. for($i = 0; $i < $queries; ++$i) {
  43. $worlds[] = DB::table('World')->find(mt_rand(1, 10000));
  44. }
  45. return Response::json($worlds);
  46. });
  47. Route::get('/fortunes', 'bench@fortunes');
  48. /*
  49. |--------------------------------------------------------------------------
  50. | Application 404 & 500 Error Handlers
  51. |--------------------------------------------------------------------------
  52. |
  53. | To centralize and simplify 404 handling, Laravel uses an awesome event
  54. | system to retrieve the response. Feel free to modify this function to
  55. | your tastes and the needs of your application.
  56. |
  57. | Similarly, we use an event to handle the display of 500 level errors
  58. | within the application. These errors are fired when there is an
  59. | uncaught exception thrown in the application. The exception object
  60. | that is captured during execution is then passed to the 500 listener.
  61. |
  62. */
  63. Event::listen('404', function()
  64. {
  65. return Response::error('404');
  66. });
  67. Event::listen('500', function($exception)
  68. {
  69. return Response::error('500');
  70. });
  71. /*
  72. |--------------------------------------------------------------------------
  73. | Route Filters
  74. |--------------------------------------------------------------------------
  75. |
  76. | Filters provide a convenient method for attaching functionality to your
  77. | routes. The built-in before and after filters are called before and
  78. | after every request to your application, and you may even create
  79. | other filters that can be attached to individual routes.
  80. |
  81. | Let's walk through an example...
  82. |
  83. | First, define a filter:
  84. |
  85. | Route::filter('filter', function()
  86. | {
  87. | return 'Filtered!';
  88. | });
  89. |
  90. | Next, attach the filter to a route:
  91. |
  92. | Route::get('/', array('before' => 'filter', function()
  93. | {
  94. | return 'Hello World!';
  95. | }));
  96. |
  97. */
  98. Route::filter('before', function()
  99. {
  100. // Do stuff before every request to your application...
  101. });
  102. Route::filter('after', function($response)
  103. {
  104. // Do stuff after every request to your application...
  105. });
  106. Route::filter('csrf', function()
  107. {
  108. if (Request::forged()) return Response::error('500');
  109. });
  110. Route::filter('auth', function()
  111. {
  112. if (Auth::guest()) return Redirect::to('login');
  113. });