-
-
Save thangngoc89/5e966946365418ca7bee to your computer and use it in GitHub Desktop.
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
// Database connector | |
<?php | |
use Illuminate\Database\Capsule\Manager as Capsule; | |
/** | |
* Configure the database and boot Eloquent | |
*/ | |
global $capsule; | |
$capsule = new Capsule; | |
$capsule->addConnection(array( | |
'driver' => getenv('DB_DRIVER'), | |
'host' => getenv('DB_HOST'), | |
'database' => getenv('DB_DATABASE'), | |
'username' => getenv('DB_USERNAME'), | |
'password' => getenv('DB_PASSWORD'), | |
'charset' => getenv('DB_CHARSET'), | |
'collation' => getenv('DB_COLLATION'), | |
'prefix' => getenv('DB_PREFIX'), | |
)); | |
$capsule->setAsGlobal(); | |
$capsule->setEventDispatcher(new Dispatcher()); | |
$capsule->bootEloquent(); | |
// Test Model | |
<?php | |
use Illuminate\Database\Eloquent\Model as Eloquent; | |
class Test extends Eloquent { | |
protected $table = 'test'; | |
protected $hidden = array(); | |
protected $fillable = array('id', 'title'); | |
protected $nullable = []; | |
public $timestamps = false; | |
public static function boot() { | |
parent::boot(); | |
static::creating(function($test){ | |
write_log('model event creating', 'model_event'); | |
}); | |
} | |
} | |
// Test Controller | |
//$test = Test::create(['title' => 'test']); | |
//$test = Test::insert(['title' => 'test']); | |
$test = new Test; | |
$test->title = 'test'; | |
$test->save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment