'Setting up Laravel in my framework: A facade root has not been set
I have been using and setting up Laravel ORM in my framework and have hit upon this error: A facade root has not been set.
I currently have database functionality with working code however other classes such as Crypt and Schema throw this error. See my implementation below.
Edit: Here is a one-script example with the problem displayed:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
include('vendor/autoload.php');
$capsule = new Illuminate\Database\Capsule\Manager;
$capsule->addConnection([
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => '*********',
'username' => '*********',
'password' => '*********',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'prefix' => '',
]);
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
class GameDatabase extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public static function up()
{
Schema::create('users', function (Blueprint $table) {
// table properties
$table->engine = 'InnoDB';
$table->charset = 'utf8mb4';
$table->collation = 'utf8mb4_unicode_ci';
// table columns
$table->id();
$table->string('name', 64)->unique();
$table->string('email', 128)->unique();
$table->string('countryCode', 4);
$table->string('mobile', 14)->unique();
$table->string('password', 40);
$table->string('password', 40);
$table->boolean('verified');
$table->dateTime('verifiedTime', 0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('flights');
}
}
$db = new GameDatabase();
$db->up();
?>
Here is composer.json
{
"require": {
"doctrine/orm": "*",
"doctrine/dbal": "^3.2",
"doctrine/annotations": "1.13.2",
"symfony/yaml": "^5.4",
"symfony/cache": "^5.4",
"doctrine/cache": "^1.11",
"illuminate/database": "^9.4"
},
"autoload": {
"psr-0": {"": "src/"}
}
}
Any advice here appreciated.
Solution 1:[1]
You may try to use Capsule::schema() instead of Schema facade.
Solution 2:[2]
Add in your bootstrap/app.php this line: $app->withFacades(); please.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tomasz Kisiel |
| Solution 2 | Maik Lowrey |
