Daniel Coulbourne - Put Verbs in your database - Laracon AU 2023

2 min read 1 year ago
Published on May 20, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Step-by-Step Tutorial: Putting Verbs in Your Database

Introduction:

In this tutorial, we will explore the concept of event sourcing and how to implement it in a Laravel application based on the insights shared in the YouTube video by Daniel Coulbourne titled "Put Verbs in your database - Laracon AU 2023."

Step 1: Understanding the Problem Statement

  • Daniel receives an email from Harry NH HR requesting to handle job applications internally.
  • Harry wants to intake new applications, approve or deny them, sort by approval status and date, schedule interviews, and send notifications.

Step 2: Implementing Event Sourcing

  • Event sourcing involves storing data in the form of events and projecting them into different shapes for easy querying and refactoring.
  • Events capture what happened in the system, allowing easy modifications and tracking of changes over time.

Step 3: Creating Laravel Models and Events

  • Create Laravel models for applications and interviews.
  • Implement events like ApplicationSubmitted, ApplicationApproved, and ApplicationRejected to handle application status changes.

Step 4: Implementing Business Logic

  • Implement business logic to validate application status transitions (e.g., cannot approve an already approved application).
  • Use event listeners to trigger actions like sending emails for scheduled interviews.

Step 5: Testing and Validation

  • Write unit tests to validate the behavior of events and state transitions.
  • Ensure that the application behaves as expected when events are triggered and state changes occur.

Step 6: Handling Errors and Edge Cases

  • Handle exceptions and edge cases like rejecting an already approved application or approving a rejected application.
  • Refactor code to improve design and prevent invalid state transitions.

Step 7: Finalizing Event Sourcing Implementation

  • Ensure that events are handled correctly, and state transitions are validated.
  • Test the application thoroughly to verify that events are triggered, and actions are performed as expected.

Step 8: Debugging and Troubleshooting

  • Debug any issues that arise during implementation.
  • Use Laravel's debugging tools and logs to identify and resolve any errors in the event sourcing implementation.

Step 9: Conclusion

  • Event sourcing allows for flexible data storage and easy tracking of changes over time.
  • By implementing event sourcing in Laravel applications, developers can simplify data management and improve system scalability.

By following these steps, you can implement event sourcing in your Laravel application based on the insights shared in the YouTube video by Daniel Coulbourne.