Skip to content

Instantly share code, notes, and snippets.

@douglascabral
Created August 19, 2016 14:35
Show Gist options
  • Select an option

  • Save douglascabral/c1d7d58783a6582e78332498a122dedd to your computer and use it in GitHub Desktop.

Select an option

Save douglascabral/c1d7d58783a6582e78332498a122dedd to your computer and use it in GitHub Desktop.
Eloquent outside Laravel
{
"require": {
"illuminate/database": "*"
}
}
<?php
require 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'test',
'username' => 'test',
'password' => 'l4m3p455w0rd!',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
));
$capsule->bootEloquent();
<?php
include 'database.php';
// Create the Books model
class Books extends Illuminate\Database\Eloquent\Model {
public $timestamps = false;
}
// Grab a book with an id of 1
$book = Books::find(1);
// Change some stuff
$book->name = "The Best Book in the World";
$book->author = "Ed Zynda";
// Save it to the database
$book->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment