Muhammad Sulman
Muhammad Sulman

Reputation: 1681

How to change Laravel-Nova action name?

Actually, I need to change the laravel nova action name like translate into different languages.

class PrintWithDetail extends Action
{
    use InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields, Collection $models)
    {
        $id = '';
        //
        foreach ($models as $model) {
            $id = $model->id;
        }
        return Action::openInNewTab(route("print.work.order", [$id, 'type' => 'detail']));
    }

}

Above action show PrintWithDetail as name.

But, I need to change PrintWithDetail into dutch.

Upvotes: 3

Views: 3574

Answers (1)

Salim Djerbouh
Salim Djerbouh

Reputation: 11044

Override the public property $name

/**
 * The displayable name of the action.
 *
 * @var string
 */
public $name;

So in your example

class PrintWithDetail extends Action
{
    use InteractsWithQueue, Queueable, SerializesModels;

    public $name = "Print met detail";

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields, Collection $models)
    {
        $id = '';

        foreach ($models as $model) {
            $id = $model->id;
        }
        return Action::openInNewTab(route("print.work.order", [$id, 'type' => 'detail']));
    }
}

You can see all what you can change in the class the action extends in nova/src/Actions/Action.php

Update

If you need the name localized in other languages, you may override the method name return a string from the Laravel __() helper method

/**
 * Get the displayable name of the action.
 *
 * @return string
 */
public function name()
{
    return __('Print with details');
}

Upvotes: 10

Related Questions