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

Synchro's avatar

Creating new items without using create

I have a model where you can't create new instances via a regular Model::create call because it needs to be created within a DB transaction that allocates serial numbers atomically. In the rest of my app, I have wrapped this in an action which I call when I need new instances. When I click "create" in Nova, it creates the object directly, bypassing this wrapper and I end up with an item without a serial number. I have seen the option to create an observer, but that only seems to receive a notification that it's calling the create method (i.e. too late) rather than substituting for it.

How can I intercept this method, or substitute my own action in place of the normal create call, so that the regular Nova create button works as normal?

0 likes
1 reply
Synchro's avatar
Synchro
OP
Best Answer
Level 2

I came up with a workaround. I have disabled "create" buttons for this Model by adding:

public static function authorizedToCreate(Request $request)
{
    return false;
}

Then I made an action that can be used to create instances instead, and this allows me to make use of my wrapper. As an added bonus, that also lets me create many items at once.

Please or to participate in this conversation.