How to capitalize the first letter in Laravel Blade Views?


October 17, 2020 02:11 PM

Hi artisans!

I want to capitalize the first letter of some strings directly in my blade view.

I know that I can do this in my controller with Str::ucfirst() but do I have to use the Str class in all of my blade views as well?

Any help will be appreciated!

Select One:

October 17, 2020 02:13 PM

Best Answer

Hey there!

What I usually do is to use the ucfirst() PHP function directly in your Blade view.

To do that in your view directly, you can use the following syntax:

{{ ucfirst('your string here') }}

Or you could even pass in a variable if you had to:

{{ ucfirst($user->first_name) }}

For more information make sure to check out the official documentation here:

Hope that this helps!

Select One:

October 17, 2020 08:12 PM

@bobbyiliev wrote a good answer. But if you want to use pure PHP you can always do that.

{{ mb_strtoupper(mb_substr($user->first_name, 0, 1)) . mb_substr($user->first_name, 1) }}

Which is really what ucfirst() does under the hood. But you can use pure PHP functions in your blade files so wanted to point this out too. 🙂

Select One:

Markdown Basics

DevDojo uses Markdown syntax for writing posts, commments, and other content throughout the site. Below you will find some commonly used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet

Bold & Italic

Italics *asterisks*

Bold **double asterisks**


Inline Code `backtick`

Code Block

Three back ticks and then enter your code blocks here.


# This is Heading 1
## This is Heading 2
### This is Heading 3
#### This is Heading 4
##### This is Heading 5

Here is an example of how each heading will looks

Heading 1

Heading 2

Heading 3

Heading 4
Heading 5


> type a greater than sign and start typing your quote.


You can add links by typing the alt text inside of [] and the link inside of (), like so:



You can add images by selecting the image icon, which will upload and add an image to the editor, or you can manually add the image by adding an exclamation !, followed by the alt text inside of [], and the link inside of (), like so:

![alt text for image](

Embedding Codepens

You can also embed a codepen pen by writing the following:

{% codepen %}

You may also choose the default tabs you wish to show your pen by writing the default-tab like so: (default is result)

{% codepen default-tab=result,html %}

Embedding YouTube Videos

You can also embed a YouTube video by writing the following:

{% youtube VIDEO_ID_HERE %}

Embedding Katacoda Terminal

You can also embed a Katacoda Terminal by writing the following:

{% katacoda %}

You may also choose if the terminal should float at the bottom of the page or be embeded in the post itself by writing float like so:

{% katacoda float %}

Embedding Asciinema

You can also embed an Asciinema video by writing the following:

{% asciinema YOUR_VIDEO_ID %}

You may also choose if the video should be added as an alternate rel tag, so it could later on be played with the `asciinema play https://devdojo/post-name` command, with the rel argument like so:

{% asciinema YOUR_VIDEO_ID rel %}

Embedding Gists

You can also embed a Gists by writing the following:

{% gist GIST_ID_HERE %}


You can also embed your "Buy me a coffee" button by writing the following:

{% buymeacoffee BUY_ME_A_COFFEE_USERNAME_HERE %}

Embedding CodeSandbox

You can also embed CodeSandbox by writing the following:



{% codesandbox %}

That's about it. It's time to start crafting your story.

Please login, or signup to write a response.

Back to DevDojo