예제 #1
0
 /**
  * Format a collection of items for our Vue viewmodel.
  * @param  Builder $query
  * @param  int     $perPage Number of items to show per page
  * @return array   Ready for JSON array of item data
  */
 public function scopePagedJson($query, $perPage)
 {
     $items = $query->orderby('pub_date', 'desc')->paginate($perPage);
     $json_data = $items->toArray();
     unset($json_data['data']);
     foreach ($items as $item) {
         $json_data['items'][] = ['date' => $item->pub_date->diffForHumans(), 'source' => $item->source(), 'title' => $item->title, 'categories' => $item->categories, 'link' => $item->link, 'id' => $item->id, 'viewed' => $item->viewed];
     }
     return $json_data;
 }