Troubleshooting
Backend Issues
"SQLSTATE: Connection refused" when starting the API
Cause: PostgreSQL is not running or the connection config is wrong.
Fix:
- Ensure PostgreSQL is running (check Laragon or system services).
- Verify
.envdatabase credentials:DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=hrms
DB_USERNAME=postgres
DB_PASSWORD=your_password - Test the connection:
php artisan db:monitor
"Class not found" or autoload errors
Fix:
composer dump-autoload
php artisan clear-compiled
Migrations fail with "relation already exists"
Cause: Database already has tables from a previous run.
Fix: Reset the database (development only):
php artisan migrate:fresh --seed
This drops all tables and recreates them. Never run this in production.
CORS errors when frontend calls the API
Cause: The frontend URL is not in the allowed origins.
Fix: Check config/cors.php and .env:
FRONTEND_URL=http://localhost:3000
SANCTUM_STATEFUL_DOMAINS=localhost:3000
SESSION_DOMAIN=localhost
419 "CSRF token mismatch"
Cause: The frontend is not sending the XSRF-TOKEN cookie or not hitting /sanctum/csrf-cookie first.
Fix:
- Ensure the frontend calls
GET /sanctum/csrf-cookiebefore login. - Check that
SESSION_DOMAINin.envmatches the frontend domain. - Verify
SANCTUM_STATEFUL_DOMAINSincludes the frontend host:port. - Ensure cookies are being sent with
credentials: 'include'.
403 "This action is unauthorized"
Cause: The logged-in user doesn't have the required permission.
Fix:
- Check the user's role:
php artisan tinker→User::find(1)->roles - Check role permissions:
Role::findByName('HR')->permissions->pluck('name') - If needed, assign permissions via the Roles UI or Tinker.
File uploads fail with "too large"
Cause: PHP or web server limits are too low.
Fix: Update php.ini:
upload_max_filesize = 10M
post_max_size = 12M
Restart the web server after changes.
Frontend Issues
Blank page after login
Cause: API URL mismatch or CORS issue.
Fix:
- Check
.env.localin the frontend:NEXT_PUBLIC_API_URL=http://localhost:8000 - Check browser console for CORS or network errors.
- Ensure the backend is running on the expected port.
"Network Error" or "Failed to fetch"
Cause: Backend is not running, or wrong API URL.
Fix:
- Verify the backend is running:
curl http://localhost:8000/api/user - Check that
NEXT_PUBLIC_API_URLis correct. - Check for proxy or firewall issues.
Styles look broken or missing
Fix:
npm run dev
If still broken, clear the Next.js cache:
rm -rf .next
npm run dev
TypeScript errors after pulling new code
Fix:
npm install
npx tsc --noEmit
Email / Notification Issues
Emails not being sent
Cause: Mail server not configured or not running.
Fix for development:
- Install smtp4dev
- Run it:
smtp4dev - Configure
.env:MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=2525 - Open smtp4dev UI at
http://localhost:5000to see captured emails.
Notifications not appearing in-app
Fix:
- Check that the notification event is enabled in Notification Settings.
- Verify the
notificationstable has records:php artisan tinker→Notification::count() - Check browser console for API errors on the notifications endpoint.
Database Issues
Seeder fails with duplicate key
Cause: Running seeder on a database that already has data.
Fix:
php artisan migrate:fresh --seed
Slow queries
Fix:
- Enable query logging: Check
storage/logs/laravel.log - Add database indexes for frequently filtered columns
- Check for N+1 queries using Laravel Telescope or debug bar
General Tips
- Always check
storage/logs/laravel.logfor backend errors. - Use browser Developer Tools (F12) → Network tab to inspect API calls.
- Run
php artisan config:clearafter changing.envvalues. - Run
php artisan cache:clearafter configuration changes. - Use
php artisan tinkerfor quick database queries and debugging.