0

I am trying to create a custom button at the bottom of a resource that will save the record and then take all of the information in that record and duplicate it into another record.

Laravel Nova Buttons

This duplicated/copied information would then give the user a jumpstart to enter another record. Right now the only actions on the Create and Update pages are Create/Update, Create/Update and Add Another but those two buttons don't fit all circumstances. And the last option just provides a blank form. I want the previously entered information to be auto-added to the form to save time.

And I am aware of the replicate function. But this requires the record to be saved and the user to return to the record and then select the replicate option. When I have users entering hundreds of items at a time, this extra step is very time consuming.

Can somebody help me figure out a way to add additional buttons to the forms so that I can extend the create and update functionality?

2
  • What have you tried so far? Commented Jun 26, 2024 at 6:58
  • @SimonC I've tried very little honestly because I cannot find any documentation on how to manipulate this area of Nova. Commented Jun 27, 2024 at 10:35

1 Answer 1

0

If you need a quick solution to pre-hydrate the form fields for a new resource with the same values as the last resource created, you could try something like:

public function fields(NovaRequest $request) {

    $latestResource = null;
    if ($request->isCreateOrAttachRequest()) {
        $latestResource = Account::latest('id')->first();
    }

    return [
        ID::make()->sortable(),

        Text::make(__('First Name'), 'first_name')
            ->withMeta([
                'value' => $latestResource ? $latestResource->first_name : $this->first_name
            ]),

        Text::make(__('Last Name'), 'last_name')
            ->withMeta([
                'value' => $latestResource ? $latestResource->last_name ??  $this->last_name
            ]),
     ];
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is a curious approach, but the client doesn't always want to perform this function. Sometimes they want a Save and New (which the out-of-the-box functionality facilities) and other times they want a Save and Replicate. I'm amazed there isn't a simple way to just add an additional button to the buttons at the bottom of the form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.