$files
The $files object extends the general Collection class and refers to a collection of files, i.e. images, documents etc. Files can be filtered, searched, converted, modified or evaluated with the following methods:
- 
    
      
      new Files()
- 
    
      
      $files->add()
- 
    
      
      $files->append()
- 
    
      
      $files->callMethod()
- 
    
      
      $files->changeSort()
- 
    
      
      $files->chunk()
- 
    
      
      $files->clone()
- 
    
      
      $files->count()
- 
    
      
      $files->current()
- 
    
      
      $files->data()
- 
    
      
      $files->empty()
- 
    
      
      $files->extend()
- 
    
      
      Files::factory()
- 
    
      
      $files->filter()
- 
    
      
      $files->filterBy()
- 
    
      
      $files->find()
- 
    
      
      $files->findBy()
- 
    
      
      $files->findById()
- 
    
      
      $files->findByKey()
- 
    
      
      $files->first()
- 
    
      
      $files->flip()
- 
    
      
      $files->get()
- 
    
      
      $files->getAttribute()
- 
    
      
      $files->getIterator()
- 
    
      
      $files->group()
- 
    
      
      $files->groupBy()
- 
    
      
      $files->has()
- 
    
      
      $files->hasMethod()
- 
    
      
      $files->indexOf()
- 
    
      
      $files->intersection()
- 
    
      
      $files->intersects()
- 
    
      
      $files->isEmpty()
- 
    
      
      $files->isEven()
- 
    
      
      $files->isNotEmpty()
- 
    
      
      $files->isOdd()
- 
    
      
      $files->key()
- 
    
      
      $files->keyOf()
- 
    
      
      $files->keys()
- 
    
      
      $files->last()
- 
    
      
      $files->limit()
- 
    
      
      $files->map()
- 
    
      
      $files->next()
- 
    
      
      $files->niceSize()
- 
    
      
      $files->not()
- 
    
      
      $files->nth()
- 
    
      
      $files->offset()
- 
    
      
      $files->paginate()
- 
    
      
      $files->pagination()
- 
    
      
      $files->parent()
- 
    
      
      $files->pluck()
- 
    
      
      $files->prepend()
- 
    
      
      $files->prev()
- 
    
      
      $files->query()
- 
    
      
      $files->random()
- 
    
      
      $files->remove()
- 
    
      
      $files->rewind()
- 
    
      
      $files->search()
- 
    
      
      $files->set()
- 
    
      
      $files->shuffle()
- 
    
      
      $files->size()
- 
    
      
      $files->slice()
- 
    
      
      $files->sort()
- 
    
      
      Files::sortArgs()
- 
    
      
      $files->sortBy()
- 
    
      
      $files->sorted()
- 
    
      
      $files->template()
- 
    
      
      $files->toArray()
- 
    
      
      $files->toJson()
- 
    
      
      $files->toString()
- 
    
      
      $files->valid()
- 
    
      
      $files->values()
- 
    
      
      $files->when()
- 
    
      
      $files->without()
You can extend this set of methods with custom files methods.
How to get a $files object
Before you can use the methods of the $files class, you need a $files object. To get a files object, you fetch the files you need from the $site, $page or $user object:
Note that the default sorting order of files is according to their order in the file system. To sort files by their manual sorting order, you can use $files->sortBy('sort'), where sort is the field that stores the sorting number if you manually sort files in the Panel.
Site files
$files = $site->files();Page files
$files = $page->files();User files
$files = $user->files();Examples:
With the $files object defined, you can now do all sorts of things:
Filter files
$filteredFiles = $files->filterBy('template', 'cover');Group files
$groupedFiles = $files->groupBy('template');Get the first file of the collection
$firstFile = $files->first();Only get three files
$files = $files->limit(3);