In this post, Iโll share how I developed a small but complete comment system in Laravel 12, focused on authentication, data validation, and basic security.
The project is called Pet Shop โ Comment System, and it was a great opportunity to practice good coding practices and understand Laravelโs core features.
๐ฏ Project Goal
The main goal was to build a functional web application that simulates a login process, comment submission, and message confirmation โ applying Laravelโs validation and security features.
I wanted to create something minimal yet complete, that demonstrates the foundations of modern Laravel development.
โ๏ธ Tech Stack
- Laravel 12 (PHP 8.2+)
 - MySQL / MariaDB
 - Bootstrap 5 (via CDN)
 - Blade Templates
 - Artisan CLI
 
๐ ID-Based Authentication
Instead of using an email address for login, I implemented authentication by ID number, a method often used in local systems.
This allowed me to create custom validation rules and flexible user management.
In the AuthController, the login logic works like this:
$request->validate([
    'cedula' => 'required|numeric',
    'password' => 'required|min:6'
]);
$user = User::where('cedula', $request->cedula)->first();
if ($user && Hash::check($request->password, $user->password)) {
    Auth::login($user);
    return redirect('/home');
} else {
    return back()->withErrors(['login' => 'Invalid credentials']);
}
This manual authentication flow helped me understand Laravelโs internals without relying on Breeze or Jetstream.
๐งฎ Arithmetic CAPTCHA
To prevent automated logins and spam, I implemented a simple arithmetic CAPTCHA that randomly generates addition, subtraction, or multiplication problems.
Hereโs a simplified version of the logic:
$num1 = rand(0, 9);
$num2 = rand(0, 9);
$operator = ['+', '-', '*'][rand(0, 2)];
switch ($operator) {
    case '+':
        $result = $num1 + $num2;
        break;
    case '-':
        $result = $num1 - $num2;
        break;
    case '*':
        $result = $num1 * $num2;
        break;
}
session(['captcha_result' => $result]);
When the user submits the form, the validation checks if the provided answer matches the stored result:
if ($request->captcha != session('captcha_result')) {
    return back()->withErrors(['captcha' => 'Incorrect CAPTCHA result.']);
}
Itโs a simple, effective solution that doesnโt require external APIs.
๐ฌ Comment System
Once logged in, users can create comments about services such as baths, walks, or grooming.
Each comment requires a minimum length and must belong to one of the predefined services.
$request->validate([
    'content' => 'required|string|min:10',
    'service' => 'required|in:banos,paseos,cortes'
]);
Comment::create([
    'user_id' => Auth::id(),
    'service' => $request->service,
    'content' => $request->content,
]);
After submission, the user is redirected to a simple confirmation view:
<h2>Comment submitted successfully ๐พ</h2>
<p>Your feedback is very important to us.</p>
๐ Project Structure
The system follows Laravelโs standard folder organization, keeping logic separated into controllers and models:
app/
โโโ Http/Controllers/
โ   โโโ AuthController.php
โ   โโโ CommentController.php
โ   โโโ HomeController.php
โโโ Models/
    โโโ Comment.php
    โโโ User.php
resources/views/
โโโ layouts/
โโโ comments/
โโโ auth/
routes/web.php
๐ Lessons Learned
- Manual authentication โ Building a login flow from scratch helps you understand Laravelโs core security features.
 - Validation rules โ Laravel Validation makes it easy to express complex rules in a clean way.
 - Lightweight CAPTCHA โ Sometimes a simple arithmetic CAPTCHA is all you need for basic security.
 - UX & Accessibility โ Clear validation messages and confirmations improve usability.
 - Simplicity matters โ Even small projects can teach big lessons about architecture and clean code.
 
๐ Next Steps
Some planned improvements include:
- Adding unit tests using Pest or PHPUnit
 - Building an admin dashboard for comment moderation
 - Integrating email notifications for confirmation messages
 
๐ถ Conclusion
This project helped me strengthen my skills in authentication, validation, and secure data handling using Laravel.
Itโs a reminder that even simple projects can teach a lot about quality, structure, and accessibility.
๐ You can check the full code here:
๐ GitHub โ Animal Shop (Pet Shop - Comment System)
Technical note: The code shown in this article is a simplified version of the real project, with minor variable name and syntax differences, but it preserves the exact same logic and functionality.
    
Top comments (0)