-1

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
Smily CK
  • 29
  • 6

2 Answers2

-1

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

Smily CK
  • 29
  • 6
  • by default, it's ``$app = require_once __DIR__.'/../bootstrap/app.php';`` unless you modified it for some reasons ! – OMi Shah Aug 23 '23 at 07:40
  • Yep this error due to many reasons, example php version changable and etc. I get error on this line so... – Smily CK Aug 23 '23 at 09:12
-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 :)

oralunal
  • 393
  • 3
  • 16
  • I already search with chatgpt but not get correct solution and then this is not working for me Thanks :) – Smily CK Aug 18 '23 at 12:27
  • The let's get deep inside. "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." We need to see the codes and what is your Laravel version? – oralunal Aug 18 '23 at 13:12
  • I got this answer – Smily CK Aug 23 '23 at 07:29