3

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

ahsan ayub
  • 286
  • 2
  • 17

2 Answers2

2

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.

ahsan ayub
  • 286
  • 2
  • 17
2

There is no need to install packages or edit core files . You can easily change this in the language files. Assuming that your app's locale is set to en, the translation file can be found in /resources/lang/vendor/nova/en.json.

In this file, go to the entry you need to edit, in this case

"Create :resource": "Create :resource"

and change the value to what you want it to be. For example, changing it to

"Create :resource": "Create a new :resource"

will turn the text into

enter image description here

  • thnks for providing this solution, i upvoted it. I hope, it will help developers, who are facing this issue. – ahsan ayub Jul 05 '20 at 07:43