How to capitalize first letter in Laravel Blade

user947668 picture user947668 · Sep 9, 2015 · Viewed 68.5k times · Source

I'm using laravel (5.1) blade template engine with the localization feature.

There is a language file messages.php within the /resources/lang/en/ folder:

return [
    'welcome' => 'welcome',

In my blade template the welcome message is called using the trans method:

{{ trans('messages.welcome') }}

In some cases I need to show the same message but with first letter capitalized ("Welcome"). I don't want to use duplicate records in the translation file.

How can I approach this?

Answer

Joseph Silber picture Joseph Silber · Sep 9, 2015

Use PHP's native ucfirst function:

{{ ucfirst(trans('messages.welcome')) }}