mardi 5 février 2019

Joining on Polymorphic relation, only one result returns

I'm trying to get achieve popular posts by locale. Below query somehow works but it's only gets one results.. In database there are four more test records exist.. Also it counts views wrong

$popularPostsByLocale = Post::select("post.id", "post.title", "post.slug",\DB::raw("SUM(views.views) as view_count"))
  ->join("views", function ($query) {
      $query->on("views.viewable_id", "post.id")
            ->where([
                 ["views.viewable_type", "App\Models\Post"],
                 ["views.locale", \LaravelLocalization::setLocale()]
            ]);
    })
    ->with("featured")
    ->where("post.status", "publish")
    ->orderBy("view_count","desc")
    ->take(5)
    ->get();

Where do I mistake and how can I fix it ?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2TyeA2t
via IFTTT

Aucun commentaire:

Enregistrer un commentaire