문제

I got a list of IDs and need to get a Collection (Let's say of the type "Book") and add Single Books to this Collection by Hand.

Example:

$ids = array(1,5,7,12);
$books = ???
foreach($ids as $id){
  $books->add(Book::find($id)); }

Or is there a easier way to get what I want?

Thank you

도움이 되었습니까?

해결책

You could write something like this I think:

$books = Book::whereIn('id', $ids)->get();

$books will be a Collection containing all your books.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top