B
B
BonBon Slick2016-11-17 20:17:01
Laravel
BonBon Slick, 2016-11-17 20:17:01

Get item by item_id from LengthAwarePaginator in Laravel 5.3?

Functions:

{{$categories->find($category->parent_id)}}
// и
{{$categories->where('category_id', $category->parent_id)}}

Does not work.
$categories->items() - will return us an array of only those that are currently displayed on the page.
dd($categories) - will return:
LengthAwarePaginator {#324 ▼
  #total: 55
  #lastPage: 11
  #items: Collection {#325 ▶}
  #perPage: "5"
  #currentPage: 1
  #path: "http://lara53/categories/5"
  #query: []
  #fragment: null
  #pageName: "page"
}

I looked here , I don’t see a function to get an element by a criterion.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrzej Wielski, 2016-11-18
@BonBonSlick

The paginator returns a certain number of elements from the database.
If you need to display to search for those elements that are displayed in the paginator, it is enough to use collections.
If you want to get an instance of an object from the entire table, use Eloquent. The paginator's response does not and will not contain all the data from the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question