filters.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. return array(
  3. /*
  4. |--------------------------------------------------------------------------
  5. | Filters
  6. |--------------------------------------------------------------------------
  7. |
  8. | Filters provide a convenient method for attaching functionality to your
  9. | routes. Filters can run either before or after a route is exectued.
  10. |
  11. | The built-in "before" and "after" filters are called before and after
  12. | every request to your application; however, you may create other filters
  13. | that can be attached to individual routes.
  14. |
  15. | Filters also make common tasks such as authentication and CSRF protection
  16. | a breeze. If a filter that runs before a route returns a response, that
  17. | response will override the route action.
  18. |
  19. | Let's walk through an example...
  20. |
  21. | First, define a filter:
  22. |
  23. | 'simple_filter' => function()
  24. | {
  25. | return 'Filtered!';
  26. | }
  27. |
  28. | Next, attach the filter to a route:
  29. |
  30. | 'GET /' => array('before' => 'simple_filter', function()
  31. | {
  32. | return 'Hello World!';
  33. | })
  34. |
  35. | Now every requests to http://example.com will return "Filtered!", since
  36. | the filter is overriding the route action by returning a value.
  37. |
  38. | To make your life easier, we have built authentication and CSRF filters
  39. | that are ready to attach to your routes. Enjoy.
  40. |
  41. */
  42. 'before' => function()
  43. {
  44. // Do stuff before every request to your application.
  45. },
  46. 'after' => function($response)
  47. {
  48. // Do stuff after every request to your application.
  49. },
  50. 'auth' => function()
  51. {
  52. if (Auth::guest()) return Redirect::to_login();
  53. },
  54. 'csrf' => function()
  55. {
  56. if (Request::forged()) return Response::error('500');
  57. },
  58. );