Getting the current row's rank with Laravel

扶醉桌前 提交于 2019-12-06 13:55:39

Although still somewhat hacky you can do it via a custom getter (mutator) in Eloquent.

public function getRankAttribute()
{
    return $this->newQuery()->where('votes', '>=', $this->votes)->count();
}

You can then get the users rank as an attribute.

$rank = Auth::user()->rank;
mpemberton5

Something like:

$currUser = DB::table('users')->where('votes','>=',Auth::user()->votes)->count();

And display $currUser by the user details below the top 10 list?

Hopefully this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!