Created
November 27, 2015 14:16
-
-
Save azraai/6fe2dff40634f3a7c1ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require '../vendor/autoload.php'; | |
// Database information | |
$settings = array( | |
'driver' => 'mysql', | |
'host' => '127.0.0.1', | |
'database' => '', | |
'username' => '', | |
'password' => '', | |
'collation' => 'utf8_general_ci', | |
'prefix' => '' | |
); | |
// Bootstrap Eloquent ORM | |
$connFactory = new \Illuminate\Database\Connectors\ConnectionFactory(); | |
$conn = $connFactory->make($settings); | |
$resolver = new \Illuminate\Database\ConnectionResolver(); | |
$resolver->addConnection('default', $conn); | |
$resolver->setDefaultConnection('default'); | |
\Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver); | |
// Create Slim app | |
$app = new \Slim\Slim(); | |
$app->get('/foo', function () { | |
// Fetch all books | |
$books = \Book::all(); | |
echo $books->toJson(); | |
// Or create a new book | |
$book = new \Book(array( | |
'title' => 'Sahara', | |
'author' => 'Clive Cussler' | |
)); | |
$book->save(); | |
echo $book->toJson(); | |
}); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment