Example #1
0
 function get_index($type = null, $object = null)
 {
     $object = (int) $object;
     $parent = $this->in('parent', null);
     if (!$this->accessible('list', $object, $parent)) {
         return false;
     }
     $rows = Post::with('author')->where('type', '=', $type)->where('object', '=', $object)->order_by('created_at', 'desc');
     "{$parent}" === '' or $rows->where('parent', '=', $parent ?: null);
     $rows = $rows->get();
     if ($rows and !$this->can('post.hidefiles')) {
         $files = File::fromLists('post', prop('id', $rows));
         $rows = S($rows, function ($model) use($files) {
             $attachments = (array) array_get($files, $model->id);
             return compact('attachments') + $model->withHTML()->to_array();
         });
     }
     return compact('rows');
 }