2017-06-16 9 views
1

私は3モデルタグ、投稿、ユーザを持っており、TagPost、TagUserモデルにマップします。laravelでのクエリの最適化クエリ

入力検索でユーザー検索タグを使用すると、$ http.post(VUE)を使用してサーバーに選択された配列タグを送信します。

例では、サーバーで印刷をタグ:

array:2 [ 
     0 => array:10 [ 
     "id" => 197 
     "name" => "nisi" 
     "slugify" => "nisi" 
     "thumbnail" => "http://lorempixel.com/400/400/?85397" 
     "seo_title" => null 
     "seo_description" => null 
     "seo_keyword" => null 
     "cover" => null 
     "created_at" => "2017-06-13 07:19:30" 
     "updated_at" => "2017-06-04 06:01:14" 
     ] 
     1 => array:10 [ 
     "id" => 184 
     "name" => "dolores" 
     "slugify" => "dolores" 
     "thumbnail" => "http://lorempixel.com/400/400/?45793" 
     "seo_title" => null 
     "seo_description" => null 
     "seo_keyword" => null 
     "cover" => null 
     "created_at" => "2017-06-08 15:37:59" 
     "updated_at" => "2017-05-27 13:34:02" 
     ] 
    ] 

ユーザー検索タグは、更新のユーザーと投稿を表示したとき、私はしたいが、タグのユーザ検索を持っています。

ここに表示:サーバー(laravel)で

enter image description here

以上のクエリを使用してリレーションシップ・モデルとコードにどのように?

+0

はマイトこれはあなたを助け、あなたの希望のデータを取得するためのロジックを実行する必要があり、あなたが正しくあなたの関係を設定していると仮定します。https:// laravel。 com/docs/5.4/eloquent-relationships –

答えて

0

これは

Tag::with('posts','users')->whereIn('id', $your_ids_send_by_vue)->get(); 

を仕事と、あなたのコントローラに