12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Repositories;
- use App\Models\Action;
- use App\Models\Enums\ActionObjectType;
- use App\Models\Enums\ObjectAction;
- use App\Models\Project;
- use Illuminate\Support\Facades\Auth;
- class ActionRepository
- {
- public static function create(
- int $objectId,
- ActionObjectType $objectType,
- ObjectAction $action,
- int|null $projectId = null,
- string $comment = null,
- array $extraFields = []
- ): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder
- {
- return Action::query()->create([
- "object_id" => $objectId,
- "object_type" => $objectType->value,
- "action" => $action,
- "project_id" => $projectId,
- "comment" => $comment,
- "extra_fields" => $extraFields ?: null,
- "created_by" => Auth::id(),
- ]);
- }
- public static function createByProject(
- Project $project,
- ObjectAction $action,
- string $comment = null,
- array $extraFields = []
- ): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder
- {
- return self::create(
- $project->id,
- ActionObjectType::PROJECT,
- $action,
- $project->id,
- $comment,
- $extraFields
- );
- }
- }
|