Search code examples
laravellaravel-nova

How to change default prefix "Create/Update" that comes with CRUD?


How can i change, prefix that comes with CRUD operation ie CREATE / UPDATE in laravel NOVA? And if i can change them, how can i apply translations on them? prefix "Create" is shown in image.

Relevant image


Solution

  • Note: You don't need to change core files, You can also do this following way

    "Create :resource": "Create :resource" to "Create :resource": "Create a new :resource" lets say resource name is post. then the new heading will become Create a new Post You can change heading the way you like from here.

    And it will update your heading, without updating core files. @Govert Verschuur provided this solution.

    Other way around is -> Default name "Create/Update" is provided in Panel.php file.

      /**
     * Get the default panel name for a create panel.
     *
     * @param  \Laravel\Nova\Resource  $resource
     * @return string
     */
    public static function defaultNameForCreate(Resource $resource)
    {
        return __('Create :resource', [
            'resource' => $resource->singularLabel(),
        ]);
    }
    
    /**
     * Get the default panel name for the update panel.
     *
     * @param  \Laravel\Nova\Resource  $resource
     * @return string
     */
    public static function defaultNameForUpdate(Resource $resource)
    {
        return __('Update :resource', [
            'resource' => $resource->singularLabel(),
        ]);
    }
    

    Change the String here and boom, it will solve your issue.

    And as far as translation is concerned is already applied, You just need to provide translation in your en.json or any other file.

    Note: Translation will only be applied on final string, so Add "Create" / "Update" with your label name and if label is not set then with your default name.