forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMysqlBook.php
36 lines (30 loc) · 920 Bytes
/
MysqlBook.php
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
30
31
32
33
34
35
36
<?php
use Illuminate\Support\Facades\Schema;
use Jenssegers\Mongodb\Eloquent\HybridRelations;
class MysqlBook extends Eloquent
{
use HybridRelations;
protected $connection = 'mysql';
protected $table = 'books';
protected static $unguarded = true;
protected $primaryKey = 'title';
public function author()
{
return $this->belongsTo('User', 'author_id');
}
/**
* Check if we need to run the schema.
*/
public static function executeSchema()
{
$schema = Schema::connection('mysql');
if (!$schema->hasTable('books')) {
Schema::connection('mysql')->create('books', function ($table) {
$table->string('title');
$table->string('author_id')->nullable();
$table->integer('mysql_user_id')->unsigned()->nullable();
$table->timestamps();
});
}
}
}