Dewa Aditya
Dewa Aditya

Reputation: 79

How to Display Single Data With Laravel 5.6

Hello everybody, Here i want to ask about how to display single row from database in view, usually we use @foreach for looping data. but here i just want to display one row.

Note : Display single row but use this eloquent ItemName::latest()

help me please, thank you :)

Upvotes: 0

Views: 324

Answers (1)

Cong LB
Cong LB

Reputation: 108

In model ItemName.php file, you could create a function. This function would return only one row by your filter.

Ex:

public static latest($itemId) {
   return self::where(['item_id' => $itemId])->orderBy('id', 'desc')->first();
}

Upvotes: 1

Related Questions