ModelNotFoundException.php 1.4 KB

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