$page->update()
Updates the page data
$page->update(array|null $input = null, string|null $languageCode = null, bool $validate = false): Page
Parameters
| Name | Type | Default |
|---|---|---|
| $input | arrayornull |
null
|
| $languageCode | stringornull |
null
|
| $validate | bool |
false
|
Return type
This method does not modify the existing $page object but returns a new object with the changes applied. Learn more →
Parent class
Examples
try {
$newPage = page('mypage')->update([
'title' => 'A new title',
'text' => 'Some text',
'anotherfield' => 'Some more data'
]);
echo 'The page has been updated:';
} catch(Exception $e) {
echo $e->getMessage();
}
Updating a field by callback
$newPage = $page->update([
'title' => function($title) {
return Str::lower($title);
}
]);
Objects as values
Each field of the page's blueprint converts Kirby objects and collections into the format it stores:
$newPage = $page->update([
'cover' => $file,
'related' => $page->siblings()->listed(),
'authors' => $kirby->users()->role('editor'),
'text' => $page->text()->toBlocks(),
'gallery' => $other->gallery(),
'date' => new DateTime(),
]);
Multi-language site
Use the optional $lang parameter to specify the language you want to update.
try {
$newPage = page('mypage')->update([
'title' => 'A new title',
'text' => 'Some text',
'anotherfield' => 'Some more data'
], 'en');
echo 'The page has been updated';
} catch(Exception $e) {
echo $e->getMessage();
}