🎓 A1Learner
🔍
0 of 50 lessons completed

Laravel Showing Data in Blade

Blade echo is the way to show a value inside a Blade view. Double curly braces print the value into the page.

Show a value

Double curly braces print a value into the page.

Hello, {{ $name }}!

Pass the value

Echo prints a value from the route into the view.

Route::get('/greet', fn () => view('greet', ['name' => 'Asha']));

Escaped HTML

Blade escapes HTML, so a tag shows as text and cannot run.

Route::get('/raw', fn () => view('greet', ['name' => '<b>Asha</b>']));

Raw HTML

Double exclamation marks print HTML without escaping it.

Hello, {!! $name !!}!

Example

Route::get('/greet', fn () => view('greet', ['name' => 'Asha']));

Hello, {{ $name }}!

Key points

  • Blade echo: the {{ }} tags that print a value into a view.
  • Use {{ $name }} to show the value of $name.
  • Use view('greet', ['name' => 'Asha']) to pass a value into a view.
  • Blade escapes HTML in echoed values, so tags show as text.

In this example, the route passes the name Asha into the greet view. The view prints the name with double curly braces. Laravel escapes the value as it prints it. The page shows Hello, Asha!.

Note

Use {!! $name !!} only for HTML you trust, because it prints raw HTML.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does {{ $name }} do in a view?