Blade Templates

Laravel blade template

The blade templet is the PHP engine provided with Laravel. the difference between blade and other PHP templating engines is 

  • The blade template allows you to  use plain PHP code in your views
  • The blade template  doesn't add any overhead to your application 
  • The blade template  files use the .blade.php extension
  • The blade template file is located in the resources/views directory.

Create a new layout using blade templet

step1: create a new file in  resources/views/home.blade.php

[IMG]

now let's add some HTML

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Home</title> 
    </head>
    <body>
        <h1>home page</h1>
    </body>
</html>

now you can add some blade magic  easily 

Echo data in Blade Template

it's very easy to echo a data in blade template, all you need to add what you want to print into a bracket {{ $name  }}   

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Home</title> 
    </head>
    <body>
        <h1>home page</h1>
            <?php $name = 'Qandeel';?>
            <p>your id is {{$name}}</p>
    </body>
</html>

If Statements in Blade Template

 Blade template provides a simple shortcut for PHP if statement, using the @if@elseif@else, and @endif directives.

example on how to use blade if statement

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Home</title> 
    </head>
    <body>
        <h1>home page</h1>
        @if(isset($id))
            <p>your id is {{$id}}</p>
        @endif
    </body>
</html>