routes.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 applications using Laravel's RESTful routing, and it
  9. | is perfectly suited for building both large applications and simple APIs.
  10. | Enjoy the fresh air and simplicity of the framework.
  11. |
  12. | Let's respond to a simple GET request to http://example.com/hello:
  13. |
  14. | Route::get('hello', function()
  15. | {
  16. | return 'Hello World!';
  17. | });
  18. |
  19. | You can even respond to more than one URI:
  20. |
  21. | Route::post('hello, world', function()
  22. | {
  23. | return 'Hello World!';
  24. | });
  25. |
  26. | It's easy to allow URI wildcards using (:num) or (:any):
  27. |
  28. | Route::put('hello/(:any)', function($name)
  29. | {
  30. | return "Welcome, $name.";
  31. | });
  32. |
  33. */
  34. Route::get('/', function()
  35. {
  36. $content = file_get_contents(path('app').'views/home/index.php');
  37. $matches = preg_match('/(\s*)@forelse(\s*\(.*\))(.+)@endforelse/m', $content);
  38. die(var_dump($matches));
  39. return View::make('home.index');
  40. });
  41. /*
  42. |--------------------------------------------------------------------------
  43. | Application 404 & 500 Error Handlers
  44. |--------------------------------------------------------------------------
  45. |
  46. | To centralize and simplify 404 handling, Laravel uses an awesome event
  47. | system to retrieve the response. Feel free to modify this function to
  48. | your tastes and the needs of your application.
  49. |
  50. | Similarly, we use an event to handle the display of 500 level errors
  51. | within the application. These errors are fired when there is an
  52. | uncaught exception thrown in the application.
  53. |
  54. */
  55. Event::listen('404', function()
  56. {
  57. return Response::error('404');
  58. });
  59. Event::listen('500', function()
  60. {
  61. return Response::error('500');
  62. });
  63. /*
  64. |--------------------------------------------------------------------------
  65. | Route Filters
  66. |--------------------------------------------------------------------------
  67. |
  68. | Filters provide a convenient method for attaching functionality to your
  69. | routes. The built-in "before" and "after" filters are called before and
  70. | after every request to your application, and you may even create other
  71. | filters that can be attached to individual routes.
  72. |
  73. | Let's walk through an example...
  74. |
  75. | First, define a filter:
  76. |
  77. | Route::filter('filter', function()
  78. | {
  79. | return 'Filtered!';
  80. | });
  81. |
  82. | Next, attach the filter to a route:
  83. |
  84. | Router::register('GET /', array('before' => 'filter', function()
  85. | {
  86. | return 'Hello World!';
  87. | }));
  88. |
  89. */
  90. Route::filter('before', function()
  91. {
  92. // Do stuff before every request to your application...
  93. });
  94. Route::filter('after', function($response)
  95. {
  96. // Do stuff after every request to your application...
  97. });
  98. Route::filter('csrf', function()
  99. {
  100. if (Request::forged()) return Response::error('500');
  101. });
  102. Route::filter('auth', function()
  103. {
  104. if (Auth::guest()) return Redirect::to('login');
  105. });