在连接时使用列作为表名

I want to get some rows from posts table. I use eloquant and, I don't know how do I make it.

I have five tables :

  • suspended_users (foreign_key - article_id -> post_translations.id)
  • post_translations (post_id (posts-reviews or specs) and post_table)
  • posts (mean contents)
  • reviews
  • specs

I want to jump those three tables from suspended_users.

And I tried to below way inside of Suspect model.

But doesn't work!

$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();

You can try to use DB::raw function. Try this:

$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();

You should try this:

$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();