-
Hi! I'm currently building a custom newsletter builder component, but we need to save content blocks and fields in separate relational tables. To do so, we need to have the model instance to link them to, so we need to wait after creation and after update to chain these blocks and fields insertions/modifications/deletions. I know there are Any help is appreciated 😃 Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Update (to be tested further): Looking at the source code, it seems like if you return a callable in Edit: It seems like the model is hydrated properly in both creation and update scenarios (thanks to PHP object properties being references). Here's a sample of how to achieve an "after save" behavior on fields: /**
* Hydrate the given attribute on the model based on the incoming request.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param string $requestAttribute
* @param object $model
* @param string $attribute
* @return mixed
*/
protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
{
return function () use ($request, $requestAttribute, $model, $attribute) {
// Some logic that needs to run after model creation/update.
};
} |
Beta Was this translation helpful? Give feedback.
Update (to be tested further): Looking at the source code, it seems like if you return a callable in
fillAttributeFromRequest
, it is executed after the model. However, I'm gonna have to explore if I can retrieve the actual saved model (with the attributed ID) from there.Edit: It seems like the model is hydrated properly in both creation and update scenarios (thanks to PHP object properties being references).
Here's a sample of how to achieve an "after save" behavior on fields: