subDays(10); $sql = <<map(fn ($post) => BlogPost::find($post->id)) ->take(16)->chunk(4); $newbiesBlogPosts = User::orderBy('created_at', 'desc') ->withCount('author_of_blog_post') ->get() ->filter(fn ($u) => $u->author_of_blog_post_count > 0)->take(4) ->pluck('id') ->map(fn ($id) => User::find($id)->author_of_blog_post()->limit(2)->get()) ->flatten() ->random(); $randomRecipe = Recipe::where('created_at', '>=', $dateMin) ->where('created_at', '<=', $dateMax) ->inRandomOrder() ->limit(2) ->get(); $firstCollection = $hotBlogPosts->first()->push($newbiesBlogPosts->first())->push($randomRecipe->first()); $secondCollection = $hotBlogPosts->skip(1)->first()->push($newbiesBlogPosts->skip(1)->first())->push($randomRecipe->skip(1)->first()); $result = $firstCollection->concat($secondCollection)->filter(fn ($el) => !is_null($el) && $el->id); return $result; } }