加入

时间:2018-08-16 11:48:00

标签: php laravel eloquent laravel-5.6

我想从posts表中获取一些行。我使用eloquant,而且我不知道该怎么做。

我有五个表:

  • 已暂停的用户(foreign_key-article_id-> post_translations.id)
  • post_translations(post_id(posts-reviewsspecs)和post_table
  • 帖子(平均内容)
  • 评论
  • 规格

我想 suspended_users中跳出这三个表。

然后我尝试在Suspect模型的内部。

但是不起作用!

$this->join("post_translations as pt", "pt.id", "=", "suspended_users.article_id")
            ->join($this->post_type." as p", "p.id", "=", "post_translations.post_id")
            ->select($this->post_type.".*")
            ->get();

2 个答案:

答案 0 :(得分:0)

您可以尝试使用DB::raw功能。试试这个:

$this->join(\DB::raw("post_translations as pt"), "pt.id", "=", "suspended_users.article_id")
            ->join(\DB::raw($this->post_type." as p"), "p.id", "=", "post_translations.post_id")
            ->select($this->post_type.".*")
            ->get();

答案 1 :(得分:0)

您应该尝试以下操作:

$this->select("p.*")->join("post_translations as pt", "pt.id", "=", "suspended_users.article_id")
            ->join($this->post_type." as p", "p.id", "=", "post_translations.post_id")
            ->get();