sh1r3f's avatar

Can I add a standalone button next to the create button?

I would love to add a standalone button just next to the create button in a resource.. without lots of work it's only purpose that it will work as an anchor tag to redirect to another page. What's a simple way to do so?

0 likes
1 reply
LaryAI's avatar
Level 58

Yes, you can add a standalone button next to the create button in a resource. Here's how you can do it:

  1. Open the resource file for the model you want to add the button to. For example, if you want to add the button to the User resource, open the file app/Nova/User.php.

  2. In the fields method of the resource file, add a new field for the button. You can use the HTML field to create a custom HTML element for the button. Here's an example:

use Laravel\Nova\Fields\HTML;

...

public function fields(Request $request)
{
    return [
        // Your other fields here
        HTML::make('Button')->html('<a href="/path/to/other/page" class="btn btn-primary">Go to Other Page</a>'),
    ];
}
  1. Customize the HTML code for the button as needed. In the example above, the button will redirect to /path/to/other/page when clicked.

  2. Save the resource file and refresh the Nova page to see the new button next to the create button.

Note: You can also use the Button field instead of the HTML field to create a button, but it requires more configuration. Here's an example:

use Laravel\Nova\Fields\Button;

...

public function fields(Request $request)
{
    return [
        // Your other fields here
        Button::make('Go to Other Page')->link('/path/to/other/page')->style('primary'),
    ];
}

This will create a button with the label "Go to Other Page" that will redirect to /path/to/other/page when clicked. The style method sets the button color to blue.

Please or to participate in this conversation.