Skip to content

Instantly share code, notes, and snippets.

@sagar290
Created May 2, 2019 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagar290/38d85fbe6f8dede85dc8dab7d9766695 to your computer and use it in GitHub Desktop.
Save sagar290/38d85fbe6f8dede85dc8dab7d9766695 to your computer and use it in GitHub Desktop.
get user position (best)
<?php
$user_id = 1; //assigned user id in $user id variable
$scores= Score::orderBy('score', 'desc')->orderBy('time', 'asc')->pluck('user_id')->toArray(); // get only user id in sorted ordered in term of score and time
$flip = array_flip($scores); // flip array index to value value to index
return $flip[(string)$user_id]+1; // add 1 because it will return index value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment