Slim is a micro web framework like
Sinatra but for PHP.
Eloquent ORMis a powerful database toolkit and it serves as a database layer of the
Lravel PHP framework. Now, this time i will install
Elequent ORM in
Slime framework and build some Restful API with it. Let’s get started!
Here is the part of
composer.json in my project:
In my project, i use the
illuminate/database 4.2 because my PHP version is 7.0 which is not support some feature like this:
[$foo, $bar] = [1,2];
But if you have higher PHP version you can try the latest
composer install to install the repo into the project.
After downloading the Eloquent we should configure it so that our application will know about it. Open the
src/config.php and add databse setting array:
'db' => [
now instantiate the capsule manager and boost Eloquent in
$dbSettings = $container->get('settings')['db'];
OK. Every thing has done, Let’s create my database model. Create
src/app/model/Goods.php file and edit:
Illuminate\Database\Eloquent\Model so it can retrieve and store data from our databse. The
$table property assigns which data table this model will use.
That’s works! Happy Hacking!