MysqlBook.php 920 Bytes
Newer Older
1 2
<?php

3 4
use Illuminate\Support\Facades\Schema;
use Jenssegers\Mongodb\Eloquent\HybridRelations;
5

Jens Segers's avatar
Jens Segers committed
6 7
class MysqlBook extends Eloquent
{
8 9
    use HybridRelations;

10
    protected $connection = 'mysql';
Jens Segers's avatar
Jens Segers committed
11 12 13
    protected $table = 'books';
    protected static $unguarded = true;
    protected $primaryKey = 'title';
14 15 16 17 18 19 20

    public function author()
    {
        return $this->belongsTo('User', 'author_id');
    }

    /**
Jens Segers's avatar
Jens Segers committed
21
     * Check if we need to run the schema.
22 23 24 25 26
     */
    public static function executeSchema()
    {
        $schema = Schema::connection('mysql');

Jens Segers's avatar
Jens Segers committed
27 28
        if (!$schema->hasTable('books')) {
            Schema::connection('mysql')->create('books', function ($table) {
29
                $table->string('title');
30 31
                $table->string('author_id')->nullable();
                $table->integer('mysql_user_id')->unsigned()->nullable();
32 33 34 35 36
                $table->timestamps();
            });
        }
    }
}