1
votes

I have created a new custom field for Laravel Nova. In the component source file I have this method:

protected function fillAttributeFromRequest(NovaRequest $request,
                                            $requestAttribute,
                                            $model,
                                            $attribute)
 {
      if ($request->exists($requestAttribute)) {
          $model->{$attribute} = json_encode($request[$requestAttribute]);
      }

  }

Is there any way that I can get the resource ID after has been saved? Is there any afterSave method or something similar?

1

1 Answers

1
votes

You could return a function from fillAttributeFromRequest it gets called after the model is created

protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
{

     return function () use ($model) {

       //$model->id model exist here

    };

}