Как изменить название акции Laravel-Nova? - PullRequest
0 голосов
/ 08 ноября 2019

На самом деле мне нужно изменить имя действия laravel nova, например перевести на разные языки.

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']));
    }

}

Выше действия показывают PrintWithDetail в качестве имени.

Но мне нужно изменить PrintWithDetail на голландский.

1 Ответ

2 голосов
/ 08 ноября 2019

Переопределить публичное свойство $name

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

Итак, в вашем примере

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']));
    }
}

Вы можете увидеть все, что вы можете изменить в классе, действие которого распространяется на nova/src/Actions/Action.php

Надеюсь, это поможет

...