-
-
Save craighooghiem/9979298 to your computer and use it in GitHub Desktop.
Using Eloquent outside of Laravel. This specific example was used in a Silex installation.
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'; | |
$settings = array( | |
'driver' => 'mysql', | |
'host' => '127.0.0.1', | |
'database' => 'database', | |
'username' => 'root', | |
'password' => 'root', | |
'collation' => 'utf8_general_ci', | |
'prefix' => '', | |
'charset' => 'utf8' | |
); | |
$connFactory = new \Illuminate\Database\Connectors\ConnectionFactory(new Illuminate\Container\Container); | |
$conn = $connFactory->make($settings); | |
$resolver = new \Illuminate\Database\ConnectionResolver(); | |
$resolver->addConnection('default', $conn); | |
$resolver->setDefaultConnection('default'); | |
\Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver); | |
/** use Eloquent **/ | |
use Illuminate\Database\Eloquent\Model as Model; | |
class Admin extends Model { | |
/** This property is required at the momment **/ | |
/** I hope this to be fixed soon **/ | |
public $table = "admin"; | |
public $timestamps = false; | |
} | |
var_dump( Admin::all() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As an alternative use https://packagist.org/packages/laravel/database which provides eloquent with migration and more to non laravel projects