public static function setRecommend() { $user_id = Auth::user()->user_id; $list_post = Post::where("user_id", '!=', $user_id)->get(); foreach ($list_post as $post) { // $list_id = (array) DB::select(DB::raw("SELECT * FROM user_posts WHERE user_id != ".$user_id." ORDER BY RAND() LIMIT 10")); $list_id = Post::where("user_id", "!=", $user_id)->orderByRaw("rand()")->distinct('photo_link')->take(5)->get(); foreach ($list_id as $id) { $recommend = new PostRecommend(); $recommend->photo_id = $post["photo_link"]; $recommend->photo_id_recommend = $id["photo_link"]; $recommend->rank = 1.0; $recommend->save(); } // print_r($post); } return $list_id; }
public function setPost() { $results = PostRecommend::setRecommend(); return $results; }