Reputation: 79
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
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