What is Laravel Blade

In Laravel framework blade is a powerful PHP templating engine system. There are many PHP template engine like Twig (for Symfony Framework), Smarty (for CodeIgniter Framework, also Twig or more can be use), Yii View (for Yii Framework). Today we will describe what is Laravel Blade and all features.

What is Blade template in Laravel

Blade is a default PHP template engine. With Laravel blade we can easily control the view in the Laravel Application.

Pass Variable in Laravel Blade from Controller

return view('create',['name' => 'Sujon Kumar Dey']); //when only view

return view('edit',compact('student'),['name' => 'Sujon Kumar Dey']);   //when compact

print on the blade {{ $name }}

Feature of Blade Template

  • Blade template prevent XSS Attack
  • CSRF protection form.
  • In blade template you can write PHP code.
  • Built in validation on form.
  • Easily variable/data transfer to blade templates


<meta name="csrf-token" content="{{ csrf_token() }}">

@php in Blade Template

//php code here

If Else in Blade Template

@if (condition)
    First one true
    Second one true
    No one true

@unless in Blade Template

@unless (condition)   //if the condition false then it's will execute the block
    Condition is not true

@isset in Blade Template

    // if variable not null then this blocks execute

@empty($variable) in Blade Template

    //if variable is empty then this block execute

@auth in Blade Template

    //if user is login this block will execute

@guest in Blade Template

    // if user is not login, mean if guest then this block will execute

@foreach in Blade Template

@foreach ($variables as $variable)
    {{ $variable->data }}

@forelse in Blade Template

@forelse ($variables as $variable)
    {{ $variable->data }}
    No data

@forelse in Blade Template

<span @class([
    'my_class_based_on_logic'  => $variable,
    'my_class_based_on_logic_2' => $variable2,


//if variable is true then class 'my_class_based_on_logic' will be work, if variable is false then class will not print

Comment in Blade

{{-- my comment --}}



Leave a Comment