跟踪多个布拉维尔(Laravel)的多个布尔人
我的关系表的迁移代码:
Schema::create('users_games', function (Blueprint $table) {
$table->bigInteger('user_id')->unsigned();
$table->index('user_id');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->bigInteger('game_id')->unsigned();
$table->index('game_id');
$table->foreign('game_id')
->references('id')
->on('games')
->onDelete('cascade');
$table->boolean('liked')->default(false);
$table->boolean('played')->default(false);
$table->boolean('wishlisted')->default(false);
// composite primary key
$table->primary(['user_id', 'game_id']);
});
基本上,用户可以标记游戏,播放或添加到愿望清单中。我想在同一表中跟踪所有这些动作。
我想在用户和游戏的Elloquent模型中代表相同的内容,但是我不知道该怎么做。谁能告诉我各自模型中应该看起来像是什么样的这些属性?
My migration code for relation table:
Schema::create('users_games', function (Blueprint $table) {
$table->bigInteger('user_id')->unsigned();
$table->index('user_id');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->bigInteger('game_id')->unsigned();
$table->index('game_id');
$table->foreign('game_id')
->references('id')
->on('games')
->onDelete('cascade');
$table->boolean('liked')->default(false);
$table->boolean('played')->default(false);
$table->boolean('wishlisted')->default(false);
// composite primary key
$table->primary(['user_id', 'game_id']);
});
basically a user can mark a game like, played or add to wishlist. I want to track all those actions in the same table.
I want to represent the same in Elloquent Model for users and games, however I dont know how to. can anyone tell me how these properties inside respective models should look like please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的用户模型中:
在您的游戏模型中:
然后,您可以从雄辩的第一个游戏中获得播放的属性的价值:
in your User Model:
in your Game model:
then you can get the value of played property from the first game in the Eloquent like this: