2017-03-24 83 views
1
ScholarCard 
    scholar_card_id   grade  scholar_id 
    1      grade-1   1 
    2      grade-1   2 
    3      grade-2   1 
    4      grade-2   2 
    5      grade-3   1 

$scholar_cards = ScholarCard::where('scholar_id','=',$scholar_id)->orderBy('scholar_card_id','DESC')->get(); 

我有一張卡片的表格,我想顯示最新創建的卡片。 就像scholar_id 1一樣,列上有三個1。你如何顯示只有 scholar_id 1的最新或最後創建。這張表只有少數記錄爲簡單起見。獲取表格中某個特定ID的最新記錄

回答

1

您可以使用first()函數。試試這個:

$scholar_card = ScholarCard::where('scholar_id','=',$scholar_id) 
          ->orderBy('scholar_card_id','DESC') 
          ->first(); 

我希望這有助於...