Today I finished the invitation flow for my team task management project.
At first, the feature looked simple: invite a user by email and let them join a team. But once I started building it, I realized there were a few real-world cases to handle.
What the invitation flow does
A team owner can invite someone using their email address.
When an invitation is sent:
- the system checks if the user is already a team member
- it checks if there is already a pending invitation for that same email in that team
- if everything is valid, an invitation record is created with a token
When the invited user accepts:
- the system verifies the logged-in user matches the invited email
- the user gets attached to the team
- the invitation gets deleted
What I learned
The biggest lesson was learning where code should live.
My controller worked, but it started getting crowded fast. It was handling:
- validation
- duplicate checks
- member checks
- creating invitations
- attaching users to teams
That pushed me to move the business logic into service classes.
Now the controller mostly handles the request and delegates the actual work.
That small refactor made the code much easier to read.
Check out the difference in the controller after using service classes.
Here’s the code for storing an invitation that I originally wrote without using a service class:
There’s a lot going on in this method, and I even duplicated Invitation::create()—that’s on me. 😅
Here’s the same method refactored using a service class:
Now it's much cleaner and easier to read. I also created Form Request class, so input validation is handled in a separate class.
One small bug that taught me something
I got stuck for a while checking duplicate invitations.
At first I used get(), which returns a collection. Even when empty, it still caused confusing behavior.
Switching to exists() made the intent much clearer.
That was a small thing, but it helped me understand Eloquent a little better.
What’s next
The invitation system is working now, and the project is starting to feel like a real application instead of just practice.
Next, I’m focusing on the frontend, starting with a cleaner dashboard and better team/project pages.
Github repo: Team Task Manager
Note: I’m using ChatGPT as part of my learning process—to sanity-check ideas, understand Laravel patterns, and think through tradeoffs. I still write the code myself and use the project to test whether I actually understand what I’m building.


Top comments (0)