-
app/Services/ProjectMemberService.php
Open in GitHubuse App\Models\Project; class ProjectMemberService { public static function getMembers(int $projectId): array { return Project::find($projectId, 'id') ->where('id', $projectId) ->with('users') ->first() ->only(['id', 'users']); } public static function syncMembers(int $projectId, array $users): array { return Project::findOrFail($projectId)->users()->sync($users); } }
-
app/Http/Controllers/Api/ProjectMemberController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Http\Requests\ProjectMember\BulkEditProjectMemberRequest; use App\Http\Requests\ProjectMember\ShowProjectMemberRequest; use App\Services\ProjectMemberService; class ProjectMemberController extends Controller { public function list(ShowProjectMemberRequest $request): JsonResponse { // ... $projectMembers = ProjectMemberService::getMembers($data['project_id']); // ... } public function bulkEdit(BulkEditProjectMemberRequest $request): JsonResponse { // ... ProjectMemberService::syncMembers($data['project_id'], $userRoles); // ... } }