0
0
Laravelframework~5 mins

Echoing data with {{ }} in Laravel

Choose your learning style9 modes available
Introduction

We use {{ }} to show data inside a Laravel Blade template. It helps display variables safely on the web page.

Showing a user's name on a profile page.
Displaying a product price in an online store.
Printing a message or alert to the user.
Showing the current date or time.
Outputting any dynamic content from your backend.
Syntax
Laravel
{{ $variable }}

This syntax automatically escapes HTML to keep your site safe from attacks.

You can put any PHP variable or expression inside the curly braces.

Examples
Displays the value of the $name variable.
Laravel
{{ $name }}
Shows the email property of a $user object.
Laravel
{{ $user->email }}
Runs a PHP function to make the $title uppercase before showing it.
Laravel
{{ strtoupper($title) }}
Calculates and displays $count plus one.
Laravel
{{ $count + 1 }}
Sample Program

This Blade template sets two variables and then shows them inside HTML using {{ }}. It will print the name and message count on the page.

Laravel
@php
  $name = 'Alice';
  $count = 3;
@endphp

<h1>Hello, {{ $name }}!</h1>
<p>You have {{ $count }} new messages.</p>
OutputSuccess
Important Notes

Always use {{ }} for output to avoid security risks like cross-site scripting (XSS).

If you want to output raw HTML, use {!! !!} but be very careful with user input.

You can use PHP inside {{ }} but keep it simple for readability.

Summary

{{ }} is the way to show data in Laravel Blade templates.

It automatically protects your site by escaping HTML.

You can display variables, object properties, and simple expressions.