【问题标题】:Laravel Eloquent Multi TablesLaravel Eloquent 多表
【发布时间】:2021-10-19 03:11:30
【问题描述】:
DB::table("game")
                ->join("game_description", "game_description.game_id", "=", "game.game_id")
                ->where("game_description.language_id", "=", getLocaleID())
                ->where("game_description.active", "=", 1)
                ->leftJoin("product_to_game", "product_to_game.game_id", "=", "game.game_id")
                ->leftJoin("product_price", "product_price.product_id", "=", "product_to_game.product_id")
                ->orderBy("product_price.product_price", "DESC");

我必须创建一个这样的查询(在 eloquent 模型中)。我必须在一个查询中连接 6-7 个表。你能帮我怎么做吗?

【问题讨论】:

  • 请不要发布代码图片,请将代码粘贴到您问题的代码块中。您需要在模型中定义关系。这在 Laravel 文档中有详细记录。
  • 请避免将代码作为图片上传为图片。 meta.stackoverflow.com/questions/285551/…

标签: php laravel eloquent model laravel-8


【解决方案1】:

您可以使用关系来连接多个表。 https://laravel.com/docs/8.x/eloquent-relationships

【讨论】:

  • 我知道我必须使用雄辩的关系但我不知道如何使用,并且没有更多资源。
猜你喜欢
  • 2019-09-06
  • 2016-03-16
  • 2016-07-22
  • 2016-03-16
  • 1970-01-01
  • 2019-06-23
  • 2019-07-21
  • 2015-02-02
  • 1970-01-01
相关资源
最近更新 更多