Just for experiment purpose. I have a self-made index.php and I have a Laravel model (made with php artisan make:model Something
) named Something.php.
How can I load Something.php into index.php and have all functionalities like if the model loaded with Laravel?
Currently I have these codes:
<?php
# This is just for testing if Laravel model can be loaded independently
require_once('../vendor/autoload.php');
require_once('../bootstrap/app.php');
require_once('OtherPackage.php');
require_once('Testimonial.php');
use Test\Sample;
use App\Testimonial;
echo 'Hello World<br />';
$s = new Sample();
$t = Testimonial::all();
echo print_r($s, true);
echo '<br />';
echo print_r($t, true);
Use php -S localhost:8080
and it has this error:
[Wed Apr 25 15:02:50 2018] ::1:58542 [500]: / - Uncaught Error: Call to a member function connection() on null in /home/notalentgeek/notalentgeek/Temporary Working Folder Here/testing-testimonial-2-without-auths/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1135
Stack trace:
#0 /home/notalentgeek/notalentgeek/Temporary Working Folder Here/testing-testimonial-2-without-auths/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1101): Illuminate\Database\Eloquent\Model::resolveConnection(NULL)
#1 /home/notalentgeek/notalentgeek/Temporary Working Folder Here/testing-testimonial-2-without-auths/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(931): Illuminate\Database\Eloquent\Model->getConnection()
#2 /home/notalentgeek/notalentgeek/Temporary Working Folder Here/testing-testimonial-2-without-auths/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(877): Illuminate\Database\Eloquent\Model->newBaseQueryBuilder()
#3 /home/notalentgeek/notalentgeek/Temporary Working Folder Here/testing-testi in /home/notalentgeek/notalentgeek/Temporary Working Folder Here/testing-testimonial-2-without-auths/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 1135
I have tried to use $app->withEloquent()
as it is told in PHP Lumen Call to a member function connection() on null. But, it returns new error:
[Wed Apr 25 15:10:08 2018] ::1:58700 [500]: / - Uncaught Error: Call to undefined method Illuminate\Foundation\Application::withEloquent() in /home/notalentgeek/notalentgeek/Temporary Working Folder Here/testing-testimonial-2-without-auths/app/index.php:10
My goal is that I want to refactor old codes with Laravel. So, I want to know what is the best way to "launch" Laravel with my old codes cover ON TOP of the Laravel project.