Laravel paginate method not working with map collection?

后端 未结 2 583
北恋
北恋 2021-02-19 09:28
$items = Item::with(\'product\')->paginate(10);

    $items = $items->map(function($product){
          $product->name = \"Test\";
          return $product; 
          


        
2条回答
  •  暖寄归人
    2021-02-19 10:18

    You should save the data in a collection, work on them, inject them back, something like this:

    $page = Input::get('page', 1);
    $data = Item::with('product')->getByPage($page, 10);
    $tempItems = $data->items;
    
    $tempItems = $tempItems->map(function($product){
          $product->name = "Test";
          return $product; 
    });
    
    
    $objects = Paginator::make($tempItems, $data->totalItems, 10);
    

提交回复
热议问题