vendredi 25 septembre 2015

Laravel 5 eloquent join based field max value

I am trying to get rows from users table and join it with Articles table on where articles.user_id = users.id and articles.view is max.

public function scopeMostViewedArticle($query)
{
    $query->leftjoin('articles as a', function ($join) {

            $join->on('a.user_id','=','users.id')
                  ->where('a.publish_date', '<',date('Y-m-d H:m'))
                  ->where('a.view','=',?);


            })
        ->groupby('users.id')
        ->orderby('users.id')
        ->select('users.*','a.title as article_title','a.image as article_image');  


}

I have problem with the '->where('a.view','=',?);' part. I appreciate your help! :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire