MysqlUser.php 901 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?php

use \Illuminate\Support\Facades\Schema;
use Jenssegers\Eloquent\Model as Eloquent;

class MysqlUser extends Eloquent {

	protected $connection = 'mysql';
    protected $table = 'users';
    protected static $unguarded = true;

    public function books()
    {
        return $this->hasMany('Book', 'author_id');
    }

    public function role()
    {
        return $this->hasOne('Role', 'role_id');
    }

    /**
     * Check if we need to run the schema
     * @return [type] [description]
     */
    public static function executeSchema()
    {
        $schema = Schema::connection('mysql');

Jens Segers's avatar
Jens Segers committed
30 31
        if (!$schema->hasTable('users'))
        {
Jens Segers's avatar
Jens Segers committed
32 33 34 35
            Schema::connection('mysql')->create('users', function($table)
            {
                $table->increments('id');
                $table->string('name');
Jens Segers's avatar
Jens Segers committed
36
                $table->timestamps();
Jens Segers's avatar
Jens Segers committed
37
            });
Jens Segers's avatar
Jens Segers committed
38
        }
39 40 41
    }

}