Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

oscar_g__'s avatar

Alter Jetstream cancelTeamInvitation action on Livewire component TeamMemberManager::class

Hi all,

I have some logic in place to stop teams from sending out invites if they are not subscribed to a premium subscription. This was done by altering App/Actions/Jetstream/InviteTeamMember.

This is fine, but it seems like cancelTeamInvitation uses the same validate function in InviteTeamMember. I want users to be able to cancel invites if they are not on a premium subscription.

So there's an edge case where

  1. User subscribes to a premium plan
  2. User sends out invitations
  3. User downgrades to basic plan
  4. User cannot cancel the invites they sent out because they are not premium

How can I alter the cancelTeamInvitation logic?

0 likes
1 reply
LaryAI's avatar
Level 58

To address the issue where users cannot cancel team invitations after downgrading from a premium subscription, you need to modify the cancelTeamInvitation method to bypass the subscription check. This can be done by customizing the TeamMemberManager Livewire component.

Here's a step-by-step solution:

  1. Create a Custom Action for Cancelling Invitations: Create a new action class that handles the cancellation of team invitations without checking the subscription status.

    namespace App\Actions\Jetstream;
    
    use Laravel\Jetstream\Contracts\DeletesTeamInvitations;
    
    class CancelTeamInvitation implements DeletesTeamInvitations
    {
        /**
         * Cancel the given team invitation.
         *
         * @param  mixed  $invitation
         * @return void
         */
        public function delete($invitation)
        {
            $invitation->delete();
        }
    }
    
  2. Register the Custom Action: Register your custom action in the JetstreamServiceProvider.

  3. Modify the TeamMemberManager Component: Update the TeamMemberManager Livewire component to use the new action for cancelling invitations.

    namespace App\Http\Livewire;
    
    use Livewire\Component;
    use Laravel\Jetstream\Jetstream;
    use Laravel\Jetstream\Contracts\DeletesTeamInvitations;
    
    class TeamMemberManager extends Component
    {
        // Other methods...
    
        /**
         * Cancel a team invitation.
         *
         * @param  int  $invitationId
         * @return void
         */
        public function cancelTeamInvitation($invitationId)
        {
            $invitation = Jetstream::findTeamInvitationOrFail($invitationId);
    
            app(DeletesTeamInvitations::class)->delete($invitation);
    
            $this->team = $this->team->fresh();
    
            $this->emit('saved');
        }
    }
    

By following these steps, you ensure that the cancelTeamInvitation method does not check the subscription status, allowing users to cancel invitations even if they are not on a premium plan. This approach keeps the logic for sending invitations and cancelling invitations separate, adhering to the single responsibility principle.

Please or to participate in this conversation.