forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMysqlUser.php
50 lines (41 loc) · 1.22 KB
/
MysqlUser.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Jenssegers\Mongodb\Eloquent\HybridRelations;
class MysqlUser extends Eloquent
{
use HybridRelations;
protected $connection = 'mysql';
protected $table = 'users';
protected static $unguarded = true;
public function books(): HasMany
{
return $this->hasMany('Book', 'author_id');
}
public function role(): HasOne
{
return $this->hasOne('Role');
}
public function mysqlBooks(): HasMany
{
return $this->hasMany(MysqlBook::class);
}
/**
* Check if we need to run the schema.
*/
public static function executeSchema(): void
{
/** @var \Illuminate\Database\Schema\MySqlBuilder $schema */
$schema = Schema::connection('mysql');
if (! $schema->hasTable('users')) {
Schema::connection('mysql')->create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
}
}
}