Created
August 19, 2016 14:35
-
-
Save douglascabral/c1d7d58783a6582e78332498a122dedd to your computer and use it in GitHub Desktop.
Eloquent outside Laravel
This file contains hidden or 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
| { | |
| "require": { | |
| "illuminate/database": "*" | |
| } | |
| } |
This file contains hidden or 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'; | |
| 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(); |
This file contains hidden or 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 | |
| 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