Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Cushty's avatar
Level 4

Change plural name dynamically

Hi i want to change my plural name for the resource based on an enum I have set up. I have checked the docs and seen I can load it dynamically

public static function getModelLabel(): string
{
    return __('filament/resources/customer.label');
}

I am a bit stumped if Filamnet has this directory made already or I need to create it myself?

Thanks

0 likes
5 replies
Tray2's avatar

So are you sayin that you have a vehicles resource, but instead you want to call it cars?

Cushty's avatar
Level 4

@Tray2 Hi, I sorted it I used the Laravel lang and did some code to show different names for different states based on the enum, thanks

  public static function getPluralModelLabel(): string
    {
        $user = Auth::user();

        if ($user instanceof User) {
            if ($user->isAdmin()) {
                return __('filament.resources.application.plural_admin');
            }

            $application = $user->application;
            if ($application && $application->status === ApplicationStatusEnum::APPROVED) {
                return __('filament.resources.application.plural_approved');
            }
        }

        return __('filament.resources.application.plural');
    }
Cushty's avatar
Level 4

@Tray2 Ah ok,

  1. is the rest of the code using __() ok? I need to tap into the enum value.
  2. Would using __() instead of a Str::plural cause any issues? I just want to understand why it's better to go with Str::. Thanks for the help.
Tray2's avatar

@Cushty It does it automatically for you, so you don't have to write the enums containing the different values.

Please or to participate in this conversation.