When I started with Laravel, I thought it would be smooth sailing after
composer create-project. Instead, I spent hours fighting silly mistakes.
Looking back, those mistakes taught me more than any tutorial. Here are
10 of them and how I fixed each one.What to expect: Real-world errors,
the exact fixes I used, and quick lessons you can apply immediately.
1) Leaving .env in public_html
- What happened: I accidentally uploaded .env to the web root, making it publicly accessible.
- Why it’s bad: Exposes DB credentials, API keys, and secrets.
- Fix: Keep .env in the project root (outside public_html) and ensure it’s in .gitignore.
# .gitignore .env
- Lesson: Security first always check what’s public.
2) Forgetting APP_KEY
3) Not
clearing config/cache after .env changes
4) Skipping storage:link (broken
images/files)
- Symptom: Uploaded files existed but wouldn’t display from
the browser.
- Fix: Create the public storage symlink.
php artisan storage:link
- Lesson: Public access to storage/app/public requires the
symlink.
5) Mixing API and web routes
- What happened: I put API-style
endpoints in web.php, hit CSRF issues and middleware confusion.
- Fix: Use
the right files and middleware.
// routes/web.php (session + CSRF)
Route::get('/', [HomeController::class, 'index'])->name('home');
// routes/api.php (stateless)
Route::get('/posts', [PostApiController::class, 'index']);
- Lesson: Keep web routes (CSRF/session) separate from stateless
API routes.
6) Hardcoding URLs instead of helpers
- Symptom: Moved from
local to production and links broke.
- Fix: Use route and asset
helpers.
- Lesson: Helpers make URLs environment-agnostic.
7)
N+1 query hell
8) Forgetting to run
migrations
9) Putting too much logic in Blade
10) Deploying without
optimizations
Bonus: Where to look first when things
break
- Check logs: storage/logs/laravel.log
- Clear caches: php artisan
config:clear, cache:clear, route:clear, view:clear
- Permissions: storage
and bootstrap/cache must be writable
Outro
Mistakes are part of the
learning curve. If you’re a junior like me, don’t be afraid of breaking
things, just make sure you learn how to fix them.