Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

syntaxerron's avatar

Laravel Custom Validation

I am currently working on Laravel project that contains transactions with different statuses and requires validation (eg If data is already submitted/approved, data cannot be cancelled). First, I validated it directly when handling request, but I also have to use it on other models, I did not want to copy and paste the same code over and over again so I changed it and created helper functions to handle these validation

I just want to know if this is appropriate? If not, what are the best practices on implementing these that can be reused on other Laravel Models as well? I am thinking on creating custom validation, but I have not found yet any resources that best apply with this concept

0 likes
2 replies
MarianoMoreyra's avatar
Level 25

Hi @erron

Without seeing any code it's kind of difficult to throw some ideas, although it seems to me that you may consider encapsulating your that logic inside a Trait that you can then use on those Models that need to apply this very same validation.

Just in case, here you have an example of implementing a Trait to reuse code for validating and storing uploaded files: https://www.develodesign.co.uk/news/laravel-traits-what-are-traits-and-how-to-create-a-laravel-trait/

Hope this helps

1 like

Please or to participate in this conversation.