-
app/Base/Exceptions/UserIsAlreadyMember.php
Open in GitHubuse Exception; class UserIsAlreadyMember extends Exception { public function render() { return response()->json([ 'status' => 'error', 'message' => 'User is already a member', ], 409); } }
-
app/Base/Http/Controllers/MemberController.php
Open in GitHubuse App\Base\Models\User; use App\Base\Exceptions\UserIsNotMember; class MemberController extends Controller { public function store() { $this->authorize('add', User::class); // Get model of team/project/office depending on request $group = $this->getGroupModel(); if ($this->userIsAlreadyMember($group, request('user_id'))) { throw new UserIsAlreadyMember; } // } // private function userIsAlreadyMember($group, $userId) { return $group->members()->where('user_id', $userId)->exists(); } // }