ActionRepository.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Action;
  4. use App\Models\Enums\ActionObjectType;
  5. use App\Models\Enums\ObjectAction;
  6. use App\Models\Project;
  7. use Illuminate\Support\Facades\Auth;
  8. class ActionRepository
  9. {
  10. public static function create(
  11. int $objectId,
  12. ActionObjectType $objectType,
  13. ObjectAction $action,
  14. int|null $projectId = null,
  15. string $comment = null,
  16. array $extraFields = []
  17. ): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder
  18. {
  19. return Action::query()->create([
  20. "object_id" => $objectId,
  21. "object_type" => $objectType->value,
  22. "action" => $action,
  23. "project_id" => $projectId,
  24. "comment" => $comment,
  25. "extra_fields" => $extraFields ?: null,
  26. "created_by" => Auth::id(),
  27. ]);
  28. }
  29. public static function createByProject(
  30. Project $project,
  31. ObjectAction $action,
  32. string $comment = null,
  33. array $extraFields = []
  34. ): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder
  35. {
  36. return self::create(
  37. $project->id,
  38. ActionObjectType::PROJECT,
  39. $action,
  40. $project->id,
  41. $comment,
  42. $extraFields
  43. );
  44. }
  45. }