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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -