【发布时间】:2019-11-01 18:46:38
【问题描述】:
我想让两种不同类型的用户能够创建相同的事件,但是该事件需要一个 user_id,这两种不同类型的用户可以共享。
我正在 Laravel 中制作一个应用程序,其中两种不同类型的用户,玩家和供应商,每个人都可以制作一个事件。
播放器
Schema::create('players', function (Blueprint $table) {
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->integer('player_id_type')->default('1');
$table->unsignedBigInteger('player_id');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
供应商
Schema::create('vendors', function (Blueprint $table) {
$table->increments('id');
$table->string('store name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
事件
Schema::create('events', function (Blueprint $table) {
$table->increments('id');
$table->string('user_id');
$table->string('name')
});
问题是玩家和供应商的 id = 1。此外,在创建事件时,我不知道是寻找具有该 id 的玩家还是供应商。
请就我如何解决这个问题或以不同的方式实施它提出一些建议。
谢谢。
【问题讨论】:
-
我可能会创建一个包含所有用户的“用户”表,并且只有一列说明它是什么类型的用户。
-
“问题是玩家和供应商的 id = 1”。要区分使用 Vendor 或 Player 的 id,您可以在查询语句中使用别名,例如:select("*","playertable.id as pID, vendortable.id as vID")
-
查看这篇文章。我认为你可以从中得到一些东西。 stackoverflow.com/questions/56642293/…
标签: php database laravel database-migration