I'm trying to use some "laravel framework" classes in other files, but I'm not getting any success.
For example:
I created a public/teste.php
file with the following code:
require __DIR__.'/../bootstrap/autoload.php';
use Illuminate\Support\Facades\DB as DB;
$dbInstance = new DB;
var_dump($dbInstance);
This gives the following return:
Object (Illuminate \ Support \ Facades \ DB) # 2 (0) {}
But when I have the following code:
require __DIR__.'/../bootstrap/autoload.php';
use Illuminate\Support\Facades\DB as DB;
$dbInstance = new DB;
var_dump($dbInstance);
$pessoas = DB::table("pessoas")->get();
var_dump($pessoas);
It gives the following result:
Fatal error: Uncaught exception 'RuntimeException' with message 'A facade root has not been set.' in C:\wamp\www\PROJETO\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:210
Stack trace:
#0 C:\wamp\www\PROJETO\public\teste.php(11): Illuminate\Support\Facades\Facade::__callStatic('table', Array)
#1 C:\wamp\www\PROJETO\public\teste.php(11): Illuminate\Support\Facades\DB::table('pessoas')
#2 {main} thrown in C:\wamp\www\PROJETO\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 210
Does anyone have any idea where I'm going wrong?
I'd like to use my Model too.