ModelNotFoundException.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Illuminate\Database\Eloquent;
  3. use RuntimeException;
  4. use Illuminate\Support\Arr;
  5. class ModelNotFoundException extends RuntimeException
  6. {
  7. /**
  8. * Name of the affected Eloquent model.
  9. *
  10. * @var string
  11. */
  12. protected $model;
  13. /**
  14. * The affected model IDs.
  15. *
  16. * @var int|array
  17. */
  18. protected $ids;
  19. /**
  20. * Set the affected Eloquent model and instance ids.
  21. *
  22. * @param string $model
  23. * @param int|array $ids
  24. * @return $this
  25. */
  26. public function setModel($model, $ids = [])
  27. {
  28. $this->model = $model;
  29. $this->ids = Arr::wrap($ids);
  30. $this->message = "No query results for model [{$model}]";
  31. if (count($this->ids) > 0) {
  32. $this->message .= ' '.implode(', ', $this->ids);
  33. } else {
  34. $this->message .= '.';
  35. }
  36. return $this;
  37. }
  38. /**
  39. * Get the affected Eloquent model.
  40. *
  41. * @return string
  42. */
  43. public function getModel()
  44. {
  45. return $this->model;
  46. }
  47. /**
  48. * Get the affected Eloquent model IDs.
  49. *
  50. * @return int|array
  51. */
  52. public function getIds()
  53. {
  54. return $this->ids;
  55. }
  56. }