$res3 = DB::table('users') ->join('user_folow_boutiques', 'user_folow_boutiques.user_id', '=', 'users.id') ->join('boutique', 'boutique.id', '=', 'user_folow_boutiques.boutique_id') ->join('type_article', 'type_article.boutique_id', '=', 'boutique.id') ->join('article', 'type_article.id', '=', 'article.type_article_id') ->join(DB::raw('(SELECT article.id c_id, count(user_aime_article.id) as nbrlik FROM article JOIN user_aime_article on user_aime_article.article_id = article.id GROUP BY user_aime_article.article_id) e'),'article.id','=','e.c_id') ->where('users.id','=',$user_id) ->where('e.nbrlik','=',50) ->select(DB::raw('article.*,article.created_at as date, e.nbrlik')) ->union($res) ->union($res2) ->groupBy('article.id') ->orderBy('date','DESC'); $sql = $res3->toSql(); $result = \DB::table(\DB::raw("($sql) as a"))->mergeBindings($res3) ->Paginate(10);
public static function getActu($user_id,$page){ $paginate = 5; // 1 selectionnée tous les article publier par les shop suivi $res = DB::table('users') ->join('user_folow_boutiques', 'user_folow_boutiques.user_id', '=', 'users.id') ->join('boutique', 'boutique.id', '=', 'user_folow_boutiques.boutique_id') ->join('type_article', 'type_article.boutique_id', '=', 'boutique.id') ->join('article', 'type_article.id', '=', 'article.type_article_id') ->where('users.id','=',$user_id) ->select(DB::raw('article.*,article.created_at as date,null as nbrlik')); // 2 Selectionnée tous les produit amai par les utilisateur suivit Arevoir demain $res2 = DB::table('users') ->join('user_follow_user', 'user_follow_user.user_id_1', '=', 'users.id') ->join('user_aime_article', 'user_follow_user.user_id_2', '=', 'user_aime_article.user_id') ->join('article', 'user_aime_article.article_id', '=', 'article.id') ->where('users.id','=',$user_id) ->select(DB::raw('article.*,user_aime_article.created_at as date, null as nbrlik') ) ->distinct(); // Selectioner tous les proiduit des boutique suivi par le user qui ont 50 j'aime $res3 = DB::table('users') ->join('user_folow_boutiques', 'user_folow_boutiques.user_id', '=', 'users.id') ->join('boutique', 'boutique.id', '=', 'user_folow_boutiques.boutique_id') ->join('type_article', 'type_article.boutique_id', '=', 'boutique.id') ->join('article', 'type_article.id', '=', 'article.type_article_id') ->join(DB::raw('(SELECT article.id c_id, count(user_aime_article.id) as nbrlik FROM article JOIN user_aime_article on user_aime_article.article_id = article.id GROUP BY user_aime_article.article_id) e'),'article.id','=','e.c_id') ->where('users.id','=',$user_id) ->where('e.nbrlik','=',50) ->select(DB::raw('article.*,article.created_at as date, e.nbrlik')) ->union($res) ->union($res2) ->groupBy('article.id') ->orderBy('date','DESC') ->skip($paginate * ($page - 1) )->take($paginate)->get(); return $res3; }