領収証発行サービス
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

90 lignes
2.2KB

  1. <?php
  2. namespace App\Models;
  3. use App\Codes\UserRole;
  4. use App\Events\Model\CreatedEvent;
  5. use App\Events\Model\DeletedEvent;
  6. use App\Events\Model\UpdatingEvent;
  7. use App\Models\Feature\ContractFeature;
  8. use App\Models\Feature\IModelFeature;
  9. use Illuminate\Database\Eloquent\Concerns\HasUuids;
  10. use Illuminate\Database\Eloquent\Factories\HasFactory;
  11. use Illuminate\Database\Query\Builder;
  12. use Illuminate\Foundation\Auth\User as Authenticatable;
  13. use Illuminate\Notifications\Notifiable;
  14. use Laravel\Sanctum\HasApiTokens;
  15. class User extends Authenticatable implements IModelFeature
  16. {
  17. use HasApiTokens, HasFactory, Notifiable, HasUuids, ContractFeature;
  18. const COL_NAME_ID = 'id';
  19. const COL_NAME_ROLE = 'role';
  20. const COL_NAME_EMAIL = 'email';
  21. /**
  22. * The attributes that should be hidden for serialization.
  23. *
  24. * @var array<int, string>
  25. */
  26. protected $hidden = [
  27. 'password',
  28. ];
  29. protected $casts = [
  30. self::COL_NAME_ROLE => UserRole::class,
  31. ];
  32. protected $dispatchesEvents = [
  33. 'created' => CreatedEvent::class,
  34. 'updating' => UpdatingEvent::class,
  35. 'deleted' => DeletedEvent::class,
  36. ];
  37. public static function getBuilder(string $name = 'main'): Builder
  38. {
  39. return DB::table(static::getTableName(), $name);
  40. }
  41. public static function getTableName(): string
  42. {
  43. return (new static)->getTable();
  44. }
  45. public function copy(IModelFeature $from): static
  46. {
  47. $data = $from->getAttributeKeys();
  48. foreach ($data as $key) {
  49. $this->$key = $from->$key;
  50. }
  51. return $this;
  52. }
  53. public function getAttributeKeys(): array
  54. {
  55. return array_values(array_unique(array_merge(array_keys($this->attributesToArray()), $this->hidden)));
  56. }
  57. public function isNotSavedModel(): bool
  58. {
  59. return data_get($this, ColumnName::ID) === null;
  60. }
  61. public function getHistory(): ?HistoryModel
  62. {
  63. return new UserHistory();
  64. }
  65. public function getModelName(): string
  66. {
  67. return "ユーザー情報";
  68. }
  69. public function getChangeLogMessage($before, $after): ?string
  70. {
  71. return null;
  72. }
  73. }