CliffordAtCaveoDotNL's avatar

Nova standalone action in the menu

Hi all,

I want to build a standalone action for converting an uploaded file into another file format and send it back to the user as a download action response. Since this action is not related to any resource, I want to put it into the menu, but it looks like this isn't possible.

Has anyone done this before?

0 likes
1 reply
LaryAI's avatar
Level 58

To create a standalone action in Laravel Nova that appears in the menu and is not tied to a specific resource, you can follow these steps:

  1. Create a Custom Tool: Nova allows you to create custom tools that can be added to the Nova sidebar. This is a good way to implement standalone functionality.

  2. Generate the Tool: Use the Artisan command to generate a new tool.

    php artisan nova:tool vendor/name
    

    Replace vendor/name with your desired namespace and tool name.

  3. Register the Tool: After generating the tool, you need to register it in the NovaServiceProvider. Open app/Providers/NovaServiceProvider.php and add your tool to the tools method:

    public function tools()
    {
        return [
            new \Vendor\Name\ToolName,
        ];
    }
    
  4. Build the Tool: Navigate to the tool's directory and run the following command to compile the tool's assets:

    cd nova-components/ToolName
    npm install
    npm run dev
    
  5. Implement the Functionality: In your tool's directory, you can implement the logic for file conversion and download. You might want to create a controller to handle the file processing and return the response.

  6. Add a Menu Link: In the tool's resources/js/tool.js file, you can define a menu link that points to your tool's page:

    Nova.booting((Vue, router, store) => {
        router.addRoutes([
            {
                name: 'tool-name',
                path: '/tool-name',
                component: require('./components/ToolComponent'),
            },
        ])
    })
    
  7. Create the Vue Component: In the resources/js/components directory, create a Vue component that will serve as the interface for your tool. This component can include a form for file upload and a button to trigger the conversion process.

  8. Handle the File Conversion: In your Laravel application, create a controller method to handle the file conversion logic. You can use Laravel's file storage and response features to process the file and return it as a download.

Here's a basic example of how you might set up the controller method:

By following these steps, you can create a standalone tool in Laravel Nova that appears in the menu and provides the functionality you need.

Please or to participate in this conversation.