Reference

Guide

$file->update()

Updates the model data

$file->update(array $input = null, string $languageCode = null, bool $validate = false): Kirby\Cms\File

Parameters

Name Type Default Description
$input array null
$languageCode string null
$validate bool false

Return type

Kirby\Cms\File

Example

if($file = $page->file('myimage.jpg')) {

  try {

    $newFile = $file->update([
      'caption' => 'This is a really nice image',
      'year'    => 2014
    ]);

    echo 'The meta info has been updated';

  } catch(Exception $e) {

    echo 'The meta info could not be updated';
    // optional reason: echo $e->getMessage();

  }

}

Multi-language installation

In a multi-language installation, you can pass the language of the meta data you want to update as a second argument:

if($file = $page->file('some-file.jpg')) {
  $newFile = $file->update([
    'some_field' => 'new value'
  ], 'en');
}

if($file = $page->file('some-file.jpg')) {
  $newFile = $file->update([
    'some_field' => 'new value'
  ], site()->language()->code());
}

Inherited from

Kirby\Cms\ModelWithContent

Source code

kirby/src/Cms/ModelWithContent.php#L676