我正試圖從得票最高的候選人那里得到他的名字,所有這些都試過失敗。在獲得所有總統候選人之后,我只是在下面添加()。Illuminate\Database\Eloquent\Collection {#288 ▼ #items: array:4 [▼ 0 => App\Candidate {#289 ▼ #connection: "mysql" #table: "candidates" #primaryKey: "id" #keyType: "int" #attributes: array:9 [▼ "id" => 1 "name" => "Brian" "seat" => "president" "regno" => "DIT-C004-0536\2013" "votes" => 0 // this is the first candidate record, others are below. "user_id" => 2 "created_at" => "2017-05-12 08:43:58" "updated_at" => "2017-05-12 08:43:58" "image" => "" ] } 1 => App\Candidate {#290 ▼ #attributes: array:9 [▼ "id" => 5 "name" => "Juma" "seat" => "president" "regno" => "DIT-C004-0516\2013" "votes" => 3 "user_id" => 7 "created_at" => "2017-05-12 09:03:03" "updated_at" => "2017-05-12 14:48:54" "image" => "" ] } 2 => App\Candidate {#291 ▼ #attributes: array:9 [▼ "id" => 9 "name" => "Stephen" "seat" => "president" "regno" => "0001" "votes" => 4 //trying to get the highest votes with the name. "user_id" => 12 "created_at" => "2020-03-17 15:27:47" "updated_at" => "2020-03-21 19:18:39" "image" => "" ] } 3 => App\Candidate {#292 ▼ #attributes: array:9 [▼ "id" => 10 "name" => "Gobby" "seat" => "president" "regno" => "DIT-C004-0436\2014" "votes" => 0 "user_id" => 11 "created_at" => "2020-03-17 15:27:59" "updated_at" => "2020-03-17 15:27:59" "image" => "" ] }我一直在四處尋找解決方案,但找不到,在此先感謝。我在循環之前轉儲了代碼,因為當我循環時它一直給我 0 或者有時告訴我數組不能轉換為 int 之類的東西。
在使用 laravel 7 獲得最高票數的候選人和他的名字時遇到問題
慕的地8271018
2023-03-11 14:04:13