Skip to main content

Employee User Invitations Process

Premium
6 min read

This lesson got separated as it's a crucial part of the application - sending out an invitation email to an employee and allowing them to register to the system:

In this lesson, we will do the following:

  • Create Invitation Model and Database tables
  • Modify UserResource Create button action - to invite the Employee
  • Email the invitation to the Employee
  • Create a custom page that will be signature (Laravel Signer URL) protected
  • Create a custom registration form for the Employee

Create Invitation Model and Database tables

Let's create our migration:

Migration

Schema::create('invitations', function (Blueprint $table) {
$table->id();
$table->string('email');
$table->timestamps();
});

Then, we can fill our Model:

app/Models/Invitation.php

class Invitation extends Model
{
protected $fillable = [
'email',
];
}

As you can see from the setup, it's a pretty basic Model. All we care about - is the email address being invited.


Modify UserResource Create Button Action - to Invite the Employee

Next on our list, we need to modify the User Create button. We don't want to create...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Ervalsa Dwi Nanda avatar

i have finish register from invitation email. but when registrating it cannot move to admin/login route and the email_verfied_at and remember_token is null so the invited account cannot used to login

Modestas avatar

In this tutorial we did not talk about the email verification, so you can add that manually.

remember me token - that does not matter, no? And for the redirect - I'm not sure what you mean

Ervalsa Dwi Nanda avatar

Thanks for you answer sir.

Ervalsa Dwi Nanda avatar

Sir, i have problem when it finish sign up, it show route [login] not defined

Modestas avatar

Could you expand on this issue? I'm not sure what the problem is

WILLY CHANDRA NEGARA avatar
WILLY CHANDRA NEGARA

Sir, i have problem when it finish sign up, it show route [login] not defined

You should sign up in different browser or just use incognito mode.

Erik Slooff avatar

Nice approach; I've been thinking about this subject for some time now and quite like your take.

Is there a reason you used a Mailable instead of a Notification (which I personally prefer)?

I'll also be looking to implement role selection when creating the invitation and making the invitation expire after a certain period, either by using temporarySignedRoute() or by setting timestamp in a column in the invitations table.

Modestas avatar

Mailable was used since we don't have an active user (I personally like to separate Notifications (user in system can receive them) and Mailables (users not in system get them)). Other than that - you can change it how you like it :)

As for the role - you can add that to invitations table for sure! That was something we specifically skipped as it depends. Everyone wants the proccess a little bit different :)

Erik Slooff avatar

Thanks, yes that totally makes sense.

Erik Slooff avatar

There appears to be a bug in this example; in AcceptInvitation.php you are Hashing the password twice. Once in the Field configuration and another time when you create the new User instance.

Modestas avatar

Oops! Updating the lesson :)

Erik Slooff avatar

Thanks, I was struggling to understand why the password didn't match until I discovered what was going on:wink:

Majd avatar

I keep getting this error: any ideas? Target [Filament\Forms\Contracts\HasForms] is not instantiable while building [Filament\Forms\Form].

Modestas avatar

Could you expand on this a bit more? I'm not sure what you were doing to get this error.

ps. Do not cross post on multiple articles ;)

Sjoerd24 avatar

In the file /app/Livewire/AcceptInvitation.php the line all the way on top:

namespace App\Livewire;

is missing. Maybe logical but I would add it for clarity. Great example btw, very useful for my project!

Edit: Wait and one other thing that i noticed, make sure that there is no identation in the blade (resources/views/emails/team-invitation.blade.php) of the email, markdown sees that as formatting. That all has to be removed.

👍 1
Solomon Iroegbu avatar

im getting this error when i try to invite a user.

Connection could not be established with host "mailpit:1025": stream_socket_client(): php_network_getaddresses: getaddrinfo for mailpit failed: No such host is known.

Modestas avatar

This error means that you have misconfigured your .env MAIL settings. Please check them and make sure they are correct

Nicolas Menescardi avatar

In here:

return Action::make('register')
->label(__('filament-panels::pages/auth/register.form.actions.register.label'))
->submit('register')

Is it possible to disable the submit button after submittion? Thanks!

Ihtisham Ahmad avatar

Property [$form] not found on component: [accept-invitation] I'm getting this error.

Modestas avatar

This usually means that the accept-invitation page is incorrectly set up. Double check that everything is there

Rafał Skonieczka avatar

I have the same :(

Unable to find component: [app.http.livewire.accept-invitation]

optimalspieler avatar

Great tutorial! How can I change the primary color, since the form is outside of my Filament panel?

->colors([
'primary' => Color::hex('#990000'),
])
optimalspieler avatar

I think I have figured it out:

https://filamentphp.com/docs/3.x/support/colors

Add this to the AppServiceProvider

public function boot(): void
{
FilamentColor::register([
'primary' => Color::hex('#990000'),
]);
}
Jeff Jeong avatar

hello thanks for the great tutorial! but i have some issue on email formatting

I have no idea how to solve this.

<table class="action" align="center" width="100%" cellpadding="0" cellspacing="0" role="presentation">

in email format Constanly getting this some <table line Do you have some suggestion??

It would be very appreciated! thanks!

Modestas avatar

I'm not sure what you have in mind here, sorry

bogusbd avatar

use this teplate for resources/views/emails/team-invitation.blade.php

without double line breaks

<x-mail::message>
You have been invited to join {{ config('app.name') }}
To accept the invitation - click on the button below and create an account:
<x-mail::button :url="$url">
{{ __('Create Account') }}
</x-mail::button>
{{ __('If you did not expect to receive an invitation to this team, you may discard this email.') }}
</x-mail::message>

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.