Skip to content

Conversation

@kevalyq
Copy link
Contributor

@kevalyq kevalyq commented Nov 22, 2025

Problem

The application was crashing with a fatal error: RuntimeException: A facade root has not been set in bootstrap/app.php at line 34. This prevented Laravel from starting correctly and also broke Laravel Boost MCP.

The error occurred because RateLimiter::for() was being called in the withMiddleware() callback in bootstrap/app.php before the application was fully booted, making facades unavailable at that point in the application lifecycle.

Solution

Moved the RateLimiter::for() calls from bootstrap/app.php to AppServiceProvider::boot() where facades are properly initialized and available.

Changes

  1. bootstrap/app.php

    • Removed RateLimiter::for() calls from withMiddleware() callback
    • Removed unused imports: Illuminate\Cache\RateLimiting\Limit, Illuminate\Http\Request, Illuminate\Support\Facades\RateLimiter
  2. app/Providers/AppServiceProvider.php

    • Added necessary imports for Limit, Request, and RateLimiter
    • Added rate limiter definitions to boot() method:
      • api rate limiter: 60 requests per minute per user/IP
      • password-reset rate limiter: 5 requests per 60 minutes per IP

Verification

  • ✅ Laravel starts correctly: php artisan --version works
  • ✅ All tests pass (444 passed)
  • ✅ Code style checks pass
  • ✅ PHPStan analysis passes
  • ✅ Laravel Boost MCP can now start properly

Impact

This is a critical bugfix that restores application functionality. No behavior changes - rate limiting configuration remains identical, just moved to the correct location in the application lifecycle.

The RateLimiter facade was being called in bootstrap/app.php before
the application was fully booted, causing a 'facade root has not been
set' fatal error. This prevented Laravel from starting correctly.

Moved the RateLimiter::for() calls from bootstrap/app.php to the
AppServiceProvider::boot() method where facades are available.

Fixes the application crash and allows Laravel Boost MCP to start.
Copilot AI review requested due to automatic review settings November 22, 2025 13:45
@github-actions
Copy link

💡 Tip: Consider Using Draft PRs

Benefits of opening PRs as drafts initially:

  • 💰 Saves CI runtime and Copilot review credits
  • 🎯 Automatically sets linked issues to "🚧 In Progress" status
  • 🚀 Mark "Ready for review" when done to trigger full CI pipeline

How to convert:

  1. Click "Still in progress? Convert to draft" in the sidebar, OR
  2. Use gh pr ready when ready for review

This is just a friendly reminder - feel free to continue as is! 😊

@codecov
Copy link

codecov bot commented Nov 22, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
app/Providers/AppServiceProvider.php 83.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot finished reviewing on behalf of kevalyq November 22, 2025 13:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical application startup error by relocating rate limiter configuration from bootstrap/app.php to AppServiceProvider::boot(). The issue occurred because facades are not available during the withMiddleware() callback in the bootstrap phase, causing a "RuntimeException: A facade root has not been set" error.

Key Changes:

  • Moved RateLimiter::for() calls from bootstrap/app.php to AppServiceProvider::boot() where facades are properly initialized
  • Updated imports accordingly in both files
  • No functional changes to rate limiting behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
bootstrap/app.php Removed rate limiter configuration and related imports from withMiddleware() callback to prevent facade initialization errors
app/Providers/AppServiceProvider.php Added rate limiter definitions to boot() method with proper facade support, maintaining identical rate limiting logic

kevalyq and others added 2 commits November 22, 2025 14:52
Co-authored-by: Copilot <175728472+Copilot[bot]@users.noreply.github.com>
The method signature is perMinutes($decayMinutes, $maxAttempts).
Therefore perMinutes(60, 5) means '5 attempts per 60 minutes' which is correct.
The previous commit incorrectly changed it to perMinutes(5, 60) which would mean '60 attempts per 5 minutes'.
@kevalyq kevalyq merged commit 9930225 into main Nov 22, 2025
17 checks passed
@kevalyq kevalyq deleted the fix/rate-limiter-facade-error branch November 22, 2025 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants