Change content from another page with 'page.update:after' hook

#1

Hi everyone!

I have a problem when trying to create a page.update:after hook. I would like to modify another page field when updating a page but I have the following error:

Exception: Error
Call to a member function find() on null
'page.update:after' => function ($newPage, $oldPage) {
    $p = $newPage->parent()->find('index');
    $p->update([
        'feeds' => $newPage->id()
    ]);
}

Apparently, the $newPage->parent() doesn’t work, but I don’t see why since this page is a child of the homepage.

Does anybody know what’s happening?

Thanks a lot!

0 Likes

#2

Is index() also a child of the home folder?

In any case, your code should contain an if-statement that checks for a page object

if($p = $newPage->parent()->find('index')) {
   $p->update([
        'feeds' => $newPage->id()
    ]);
}

But please post your folder structure so we can more easily find the problem.

0 Likes