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?
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.