Getting the current row's rank with Laravel -
in laravel 4 app, users
table has votes
column. i'd find current user's rank. can top 10 users user::orderby('votes', 'desc')->take(10)
, i'd display current user's rank below list. ideally, go like:
auth::user()->rank('orderby', 'votes', 'desc');
i logged in user, ask rank assuming order users table votes.
does know if there's way can eloquent?
although still hacky can via custom getter (mutator) in eloquent.
public function getrankattribute() { return $this->newquery()->where('votes', '>=', $this->votes)->count(); }
you can users rank attribute.
$rank = auth::user()->rank;
Comments
Post a Comment