Skip to content

Instantly share code, notes, and snippets.

@azraai
Created November 27, 2015 14:16
Show Gist options
  • Save azraai/6fe2dff40634f3a7c1ac to your computer and use it in GitHub Desktop.
Save azraai/6fe2dff40634f3a7c1ac to your computer and use it in GitHub Desktop.
<?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