Skip to content

Instantly share code, notes, and snippets.

@clauddiu
Created December 7, 2012 15:50
Show Gist options
  • Save clauddiu/4234104 to your computer and use it in GitHub Desktop.
Save clauddiu/4234104 to your computer and use it in GitHub Desktop.
Using Eloquent outside of Laravel 4 this extends gist https://gist.github.com/4107178
<?php
require 'vendor/autoload.php';
$resolver = new Illuminate\Database\ConnectionResolver;
$resolver->setDefaultConnection('default');
$factory = new Illuminate\Database\Connectors\ConnectionFactory;
$connection = $factory->make(array(
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => 'password',
'collation' => 'utf8_general_ci',
'driver' => 'mysql',
'prefix' => '',
));
$resolver->addConnection('default', $connection);
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() );
@Arul-
Copy link

Arul- commented Jun 16, 2021

As an alternative use https://packagist.org/packages/laravel/database which provides eloquent with migration and more to non laravel projects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment