skip to Main Content

I’am getting below error:

[Fri Aug 18 14:31:50 2023] PHP Fatal error: Uncaught
RuntimeException: A facade root has not been set. in
/home/…./vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:258

Laravel version is 8 and PHP version is 8

I have tried below commands too:

composer dump-autoload
composer update
php artisan config:clear

2

Answers


  1. Chosen as BEST ANSWER

    i got the answer guys, change on public/index.php file

    $app = require_once __DIR__.'/bootstrap/app.php';
    

    this to

    $app = require_once __DIR__.'/../bootstrap/app.php';
    

    slash is problem


  2. The error "A facade root has not been set" can arise due to several reasons in Laravel’s Facade structure. Here are some potential causes:

    1. Bootstrap Files Not Loaded: You may receive this error if Laravel’s core files are not loaded properly. This is often due to the autoloader not functioning correctly.
    2. Service Provider Not Registered: If you have created a service provider or a Facade and it’s not properly registered in config/app.php, you may encounter this error.
    3. Early Facade Usage: If you try to use a Facade before the application’s bootstrapping process is complete, you might get this error. For instance, using a Facade within the register method of a service provider can lead to this issue.
    4. Faulty Cache: Laravel caches certain things like configurations and routes. A faulty or outdated cache might cause such errors.

    To resolve this error, you can try the following steps:

    1. Update Composer: Start by regenerating Composer’s autoloader:
    composer dump-autoload
    
    1. Clear Cache: Clearing Laravel’s cache can sometimes solve such
      issues:
    php artisan cache:clear
    php artisan config:clear
    php artisan route:clear
    
    1. Check Service Providers and Facades: If you’ve created your own
      service providers or Facades, ensure they are properly registered in
      the config/app.php file.

    2. Revert Faulty Changes: If there’s a specific change you made before
      encountering this error, try reverting that change to isolate the
      problem.

    3. Check Logs: Laravel creates detailed logs for errors in the
      storage/logs directory. You can check these logs for more
      information about the error.

    If these steps don’t resolve your issue, sharing the specific code snippet that caused the error would help in providing a more specific solution.

    Solution by chatgpt 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search