garrettmassey's avatar

Customizing Laravel Nova's action events table

Is it possible to change the default name of the table associated with action events in Laravel Nova? Currently in Nova v4 the table name is action_events but I'd like to prepend it with nova_ so that it better matches other nova-created tables, like nova_field_attachments and nova_notifications.

0 likes
2 replies
LaryAI's avatar
Level 58

To customize the table name for action events in Laravel Nova, you can achieve this by modifying the configuration in your Nova service provider. Here's a step-by-step guide:

  1. Publish the Nova Configuration File: If you haven't already, you need to publish the Nova configuration file. Run the following command:

    php artisan vendor:publish --provider="Laravel\Nova\NovaServiceProvider"
    

    This will create a config/nova.php file where you can customize various Nova settings.

  2. Modify the Action Event Table Name: Open the config/nova.php file and look for the action_events configuration. If it doesn't exist, you can add it. Set the table key to your desired table name, like so:

    'action_events' => [
        'table' => 'nova_action_events',
    ],
    
  3. Create a Migration to Rename the Table: You will need to create a migration to rename the existing action_events table to nova_action_events. You can create a new migration using the following command:

    php artisan make:migration rename_action_events_table
    

    Then, in the generated migration file, use the rename method to rename the table:

    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class RenameActionEventsTable extends Migration
    {
        public function up()
        {
            Schema::rename('action_events', 'nova_action_events');
        }
    
        public function down()
        {
            Schema::rename('nova_action_events', 'action_events');
        }
    }
    
  4. Run the Migration: Finally, run the migration to apply the changes:

    php artisan migrate
    

By following these steps, you will have successfully changed the table name for action events in Laravel Nova to nova_action_events. Make sure to test your application to ensure everything is working as expected after making these changes.

garrettmassey's avatar

Nevermind, just found the ActionEvent model source code, and it looks like its hard coded:

ActionEvent.php

    /**
     * Get the table associated with the model.
     *
     * @return string
     */
    public function getTable()
    {
        return 'action_events';
    }

Please or to participate in this conversation.