PHPForge

The global community where PHP developers connect, learn, and build better backends together. From beginners to senior engineers — master PH...
San Jose, US
Created byProfile pictureJohn
8 joined
Profile picture
JohnProfile picture@john112key·Apr 13

5 Laravel Mistakes That Cost Me Weeks of Debugging

After 6+ years building production Laravel apps, here are the mistakes I see (and made) repeatedly — and how to avoid them.


1. Fat Controllers, Skinny Models (The Wrong Way)


Stop putting business logic in controllers. If your controller method is 50+ lines, you're doing it wrong. Move logic to Services, Actions, or model methods.


// ❌ Don't do this
public function store(Request $request) {
    $user = User::create($request->all());
    Mail::to($user)->send(new WelcomeMail());
    $user->profile()->create([...]);
    event(new UserRegistered($user));
    // 40 more lines...
}

// ✅ Do this
public function store(StoreUserRequest $request, CreateUserAction $action) {
    $user = $action->execute($request->validated());
    return redirect()->route('users.show', $user);
}


2. N+1 Queries Everywhere


If you're looping through a collection and accessing a relationship, you've probably got N+1 queries. Use with() or install beyondcode/laravel-query-detector to catch them automatically.


3. Not Using Database Transactions


If you're doing multiple related writes without wrapping them in DB::transaction(), you're asking for data inconsistency in production.


4. Ignoring Queue Jobs


Sending emails, processing images, hitting external APIs — if it takes more than 200ms, it should be a queued job. Your users shouldn't wait for Stripe webhooks to process synchronously.


5. Skipping Form Requests


Inline validation with $request->validate() is fine for prototypes. For production, use Form Request classes. They're reusable, testable, and keep controllers clean.


---


PHPForge is a community where PHP developers share real-world experience like this daily. Framework deep-dives, code reviews, architecture discussions, and direct Q&A with experienced developers.


Join free and start building better PHP today.