領収証発行サービス
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 line
1.1KB

  1. <?php
  2. namespace App\Models;
  3. use Exception;
  4. use Illuminate\Database\Eloquent\Concerns\HasUuids;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. use Illuminate\Support\Facades\Auth;
  7. use Illuminate\Support\Str;
  8. abstract class AppModel extends BaseModel
  9. {
  10. use SoftDeletes, HasUuids;
  11. public function getHistory(): ?HistoryModel
  12. {
  13. $historyName = static::class . 'History';
  14. $history = new $historyName;
  15. if ($history instanceof HistoryModel) {
  16. if (Auth::check()) {
  17. $id = Auth::id();
  18. $history->updated_by = $id;
  19. $history->created_by = $id;
  20. }
  21. return $history;
  22. } else {
  23. throw new Exception("履歴モデル不正");
  24. }
  25. }
  26. public function getChangeLogMessage($before, $after): ?string
  27. {
  28. return null;
  29. }
  30. public function setId(?string $uuid = null)
  31. {
  32. if ($this->id !== null) return;
  33. if ($uuid) {
  34. $this->id = $uuid;
  35. } else {
  36. $this->id = Str::uuid();
  37. }
  38. }
  39. }