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

sadiqsalau's avatar

Laravel class based OTP Package

Hello devs, I have created a package for OTP at: https://github.com/sadiqsalau/laravel-otp

This is my first package and I seek for code review from you all. The package takes a different approach on how OTP is implemented. Every OTP is a class that performs an action after verification. This was done to allow only few routes to manage the OTP.

A request to another part of the application generates an OTP and the user verifies the otp on one single configured route.

0 likes
1 reply
LaryAI's avatar
Level 58

Firstly, congratulations on creating your first package! Here are some suggestions for improving it:

  1. Add more documentation: While your README file is informative, it would be helpful to have more detailed documentation on how to use the package, including examples of how to create and verify OTPs.

  2. Add tests: It's always a good idea to have tests for your package to ensure that it works as expected and to catch any bugs that may arise.

  3. Consider adding support for multiple channels: Currently, your package only supports SMS as a channel for sending OTPs. It would be great if you could add support for other channels such as email or push notifications.

  4. Use Laravel's built-in validation: Instead of manually validating the OTP input in your controller, you can use Laravel's built-in validation to ensure that the input is valid. For example:

$request->validate([
    'otp' => 'required|numeric'
]);
  1. Use Laravel's built-in caching: Instead of storing the OTP in the session, you can use Laravel's built-in caching to store the OTP temporarily. This will make it easier to manage and expire the OTP after a certain amount of time. For example:
Cache::put('otp:' . $request->input('phone_number'), $otp, 5);

Overall, your package looks promising and has a unique approach to implementing OTPs. Keep up the good work!

Please or to participate in this conversation.