Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

m615's avatar
Level 2

Can I preform a Nova Action on Creation or Update of a Resource?

I have a Page resource in Nova that has an is_homepage boolean. If a User marks the Page as homepage true I would like to perform an action on saving or update in order to mark any other pages in the database that were previously set to the homepage as false?

What is the best way to accomplish this?

I'd really like to Query all other pages in the DB and perform the action before I update or save the new page as the new homepage.

Here are the steps I would like to perform.

/// User is creating or updating a Page resource
Boolean::make('Is Homepage') //sets to true

///User clicks create or update and just before update or save the following function runs

function() {
  $pages = Page::where('is_homepage', true)->get();
  
  foreach($pages as $page)
  {
      $page->is_homepage = false;
      $page->save();
  )
}

//after this action runs the update to the new or existing object is preformed
0 likes
3 replies
m615's avatar
Level 2

Perfect! Thank you. This will be the perfect solution

m615's avatar
Level 2

Question ... is there a method that will be called on an Observer no matter what? It would be nice to have one method and then check to see what type of event was called and perform different operations?

Example for my situation:

Any time the Page model is changed I want to check to see if the "is_homepage" boolean is set to true. If so I want to update all other pages to be set to false.

If Page that "is_homepage' set to true is "deleted" I want to throw an error.

Please or to participate in this conversation.