participates($user, $conversation); } /** * Determine whether the user can create models. */ public function create(User $user): bool { return true; } /** * Determine whether the user can update the model. */ public function update(User $user, Conversation $conversation): bool { return $conversation->participants() ->where('user_id', $user->id) ->where('role', ConversationParticipant::RoleAdmin) ->exists(); } /** * Determine whether the user can delete the model. */ public function delete(User $user, Conversation $conversation): bool { return $conversation->created_by_id === $user->id; } /** * Determine whether the user can restore the model. */ public function restore(User $user, Conversation $conversation): bool { return false; } /** * Determine whether the user can permanently delete the model. */ public function forceDelete(User $user, Conversation $conversation): bool { return false; } public function sendMessage(User $user, Conversation $conversation): bool { return $this->participates($user, $conversation); } private function participates(User $user, Conversation $conversation): bool { return $conversation->participants() ->where('user_id', $user->id) ->exists(); } }