InteractsWithFlashData.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Illuminate\Http\Concerns;
  3. trait InteractsWithFlashData
  4. {
  5. /**
  6. * Retrieve an old input item.
  7. *
  8. * @param string $key
  9. * @param string|array|null $default
  10. * @return string|array
  11. */
  12. public function old($key = null, $default = null)
  13. {
  14. return $this->hasSession() ? $this->session()->getOldInput($key, $default) : $default;
  15. }
  16. /**
  17. * Flash the input for the current request to the session.
  18. *
  19. * @return void
  20. */
  21. public function flash()
  22. {
  23. $this->session()->flashInput($this->input());
  24. }
  25. /**
  26. * Flash only some of the input to the session.
  27. *
  28. * @param array|mixed $keys
  29. * @return void
  30. */
  31. public function flashOnly($keys)
  32. {
  33. $this->session()->flashInput(
  34. $this->only(is_array($keys) ? $keys : func_get_args())
  35. );
  36. }
  37. /**
  38. * Flash only some of the input to the session.
  39. *
  40. * @param array|mixed $keys
  41. * @return void
  42. */
  43. public function flashExcept($keys)
  44. {
  45. $this->session()->flashInput(
  46. $this->except(is_array($keys) ? $keys : func_get_args())
  47. );
  48. }
  49. /**
  50. * Flush all of the old input from the session.
  51. *
  52. * @return void
  53. */
  54. public function flush()
  55. {
  56. $this->session()->flashInput([]);
  57. }
  58. }