Reusable Validation Rules with Laravel Form Requests

Currently I'm working on a project with a lot of forms that have repeated form fields. For example, pretty much all entities in the system can have attachments, so a lot of forms contain the same attachment fields. I could repeat the same validation rules in all form request classes, but this quickly breaks down. What if the rules for attachments change? Let's see how we can handle this more efficiently.

Read more

Testing Your Laravel Middleware

While working on an application I wanted to test my middleware. When doing some investigation on this issue I didn't find any satisfying solutions, most involved manually creating a Symfony request object or mocking the request entirely.

Read more

Writing an Allowed Username Validator in Laravel

When building a project that requires top-level public user profiles, you will have to find a way to prevent the usernames from clashing with public URLs or files. If you don't do this, it's only a matter of time before someone signs up with the username 'logout' and make everyone who clicks on the profile link logout of their account. Here's a solution that I came up with that allows you to build it once and forget about it for the rest of the project lifetime.

Read more