How to pass additional information into Laravel Jetstream team invite email

Viewed 263

I want to capture if the user already has an account in my app. I've got everything working up until the point of the team invitation email, where I can't get the value to pass. If I dd($invitation) I can see my value is there, but if I use $invitation->existing_user it doesn't display. Here is my code:

@component('mail::message')
{{ __('You have been invited to join the :team team!', ['team' => $invitation->team->name]) }}
{{ __('Existing User:') }} {{$invitation->existing_user}}

@if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::registration()))
{{ __('If you do not have an account, you may create one by clicking the button below. After creating an account, you may click the invitation acceptance button in this email to accept the team invitation:') }}

@component('mail::button', ['url' => route('register')])
{{ __('Create Account') }}
@endcomponent

{{ __('If you already have an account, you may accept this invitation by clicking the button below:') }}

@else
{{ __('You may accept this invitation by clicking the button below:') }}
@endif


@component('mail::button', ['url' => $acceptUrl])
{{ __('Accept Invitation') }}
@endcomponent

{{ __('If you did not expect to receive an invitation to this team, you may discard this email.') }}
@endcomponent

You can see on the second line what I've added, everything else is original code.

1 Answers

Send data like this from your controller

$data = [
   'team_name' => $invitation->team->name
];

Then in the view, you can get data like below.

@component('mail::message')

   {{ __('You have been invited to join the :team team!', ['team' => $data['team_name']]) }}

@endcomponent

Related