title: Having issues with getting the candidate with the highest vote and his name using laravel 7
body: <p>I Am trying to get from the candidate with the highest votes and his name also, all have tried runs false. I just dd() this below, after getting all the presidential candidates.</p>
  
  <pre><code>Illuminate\Database\Eloquent\Collection {#288 ▼
    #items: array:4 [▼
      0 =&gt; App\Candidate {#289 ▼
        #connection: "mysql"
        #table: "candidates"
        #primaryKey: "id"
        #keyType: "int"
        #attributes: array:9 [▼
          "id" =&gt; 1
          "name" =&gt; "Brian"
          "seat" =&gt; "president"
          "regno" =&gt; "DIT-C004-0536\2013"
          "votes" =&gt; 0     // this is the first candidate record, others are below.
          "user_id" =&gt; 2
          "created_at" =&gt; "2017-05-12 08:43:58"
          "updated_at" =&gt; "2017-05-12 08:43:58"
          "image" =&gt; ""
        ]
  
      }
  
      1 =&gt; App\Candidate {#290 ▼
        #attributes: array:9 [▼
          "id" =&gt; 5
          "name" =&gt; "Juma"
          "seat" =&gt; "president"
          "regno" =&gt; "DIT-C004-0516\2013"
          "votes" =&gt; 3
          "user_id" =&gt; 7
          "created_at" =&gt; "2017-05-12 09:03:03"
          "updated_at" =&gt; "2017-05-12 14:48:54"
          "image" =&gt; ""
        ]
      }
  
      2 =&gt; App\Candidate {#291 ▼
        #attributes: array:9 [▼
          "id" =&gt; 9
          "name" =&gt; "Stephen"
          "seat" =&gt; "president"
          "regno" =&gt; "0001"
          "votes" =&gt; 4           //trying to get the highest votes with the name.
          "user_id" =&gt; 12
          "created_at" =&gt; "2020-03-17 15:27:47"
          "updated_at" =&gt; "2020-03-21 19:18:39"
          "image" =&gt; ""
        ]
      }
      3 =&gt; App\Candidate {#292 ▼
        #attributes: array:9 [▼
          "id" =&gt; 10
          "name" =&gt; "Gobby"
          "seat" =&gt; "president"
          "regno" =&gt; "DIT-C004-0436\2014"
          "votes" =&gt; 0
          "user_id" =&gt; 11
          "created_at" =&gt; "2020-03-17 15:27:59"
          "updated_at" =&gt; "2020-03-17 15:27:59"
          "image" =&gt; ""
        ]
       }
  
  </code></pre>
  
  <p>I have been searching for solutions all around but couldn't find one, <strong>Thanks in Advance</strong>.</p>
  
  <p>This is my controller:</p>
  
  <pre><code>{
      public function highestvote(){
      $getpres = Candidate::where('seat','president')-&gt;get();
      dd($getpres);
      foreach($getpres as $getpresvote){
          for($i = 0; $i &lt; $getpresvote; $i++){
              $highv = $getpresvote[$i];
          }
      }
    return view('election.winners')-&gt;with('getpresvotes',$getpresvotes);
  
      } 
  }
  </code></pre>
  
  <p>I die dump the code before looping, cause when I loop it keeps on giving me 0 or sometimes tells me stuff like array can't be converted int.</p>