Quick Contact

    <h4>Laravel- Blade Template</h4>
    <p>Blade template is template engine in the Laravel that convert plain text to php code. It is needed because there are some php tags and the loops and conditions and functions which are little bit difficult to write, so blade template provide easy way to use. Such as you use “for each loop” and if conditions you use ‘@’, and if you want to echo something then you can use ‘{}’- double curly braces. </p>
    <p>- So let’s say in php tag, if you just want to echo something then you can write as – ‘< ?php echo ?>’. </p>
    <p>And in blade template just you can simply use ‘{}’- curly braces and dollar ‘i’ as-: ‘{$i}’.</p>
    <p>- So from above point you can understand that use of blade templates is simple and faster. </p>
    <p> With the help of blade template-:</p>
    <ol>
    <li>You can make header and footer or common style. </li>
    <li>If you want to load some JavaScript file in the common area so this also can be possible with blade template.</li>
    </ol>
    <h5><i>Blade Template Expressions</i></h5>
    <ol>
    <li>For this you need view and controller. </li>
    <p>- First make a controller. So as usual go to console and write “php artisan make: controller ‘controller name’” and controller will be created.</p>
    <p>- After controller is created having name as ‘userscontroller’ you will find the controller in visual studio files inside the ‘app’ > http > controllers > userscontroller.php.</p>
    <p>- Now make a function in controller as-:</p>
    </ol>
    <pre><i>
    Function viewLoad()
    {
    Return view(‘’)
    }
    </i></pre>
    <p>In return view the name of view will come when you will create a view.</p>
    <p>- Let’s make a view-:</p>
    <p> Go to resources>views> and here make file “users.blade.php” so here ‘blade’ word is important in “users.blade.php” because in “users.php” you cannot write the code in blade Templating way. So blade.php extension is important if you want to use Templating engine code right and expressions. </p>
    <p>- In users.blade.php write-:</p>
    <p>< h1> users page < /h1></p>
    <p>- Now go to web.php and define a route for it and import controller and write code as-:</p>
    <div class=”img”>
    <img src=”images/pic1.png” height=”350px” width=”600px”>
    </div>
    <p>Now see the result in browser-:</p>
    <div class=”img2″>
    <img src=”images/pic2.png” height=”200px” width=”400px”>
    </div>
    <h5><i>Now how you can use blade template in users.blade.php-:</i></h5>
    <p>Use double curly braces- ‘{{}}’ so if you like something here then it will take it as php code -:</p>
    <p>{{10+10}} and output will be-:</p>
    <div class=”img3″>
    <img src=”images/pic3.png” height=”200px” width=”400px”>
    </div>
    <p>You can also use php functions. </p>
    <P>- As if you want to pass some data from userscontroller.php in ‘function’. Code is as-:</P>
    <pre><i>
    < ?php
    Namespace App\http\Controllers;
    Use Illuminate\Http\Request;
    Class UsersController extends Controller
    {
    //
    Function viewLoad()
    {
    Return view(‘users’, [‘users’ =>[‘anil’, ‘sam’, ‘peter’]]);
    }
    }
    </i></pre>
    <p>And method is applied in user.blade.php, count method as-:</p>
    <div class=”img4″>
    <img src=”images/pic4.png” height=”280px” width=”500px”>
    </div>
    <p>Output is as-:</p>
    <div class=”img5″>
    <img src=”images/pic5.png” height=”200px” width=”400px”>
    </div>
    <p>Count is 3 because there are 3 users in usercontroller.php file. </p>
    <p>- If you use if condition then the usercontroller.php and user.blade.php files are used as-:</p>
    <p>UsersController.php code written as-:</p>
    <pre><i>
    < ?php
    Namespace App\Http\Controllers;
    Use Illuminate\Http\Controllers;
    Class UserController extends Controller
    {
    //
    Function viewLoad()
    {
    Return view(‘users’, [‘users’, [‘user’ => ‘anil’ ]);
    }
    }
    </i></pre>
    <p>Users.blade.php code is written as-:</p>
    <p>< h1> Users Page < /h1></p>
    <p>@if($user == “anil”)</p>
    <p>< h3> Hi {{$user}} < /h3></p>
    <p>Output will be as-:</p>
    <div class=”img6″>
    <img src=”images/pic6.png” height=”200px” width=”400px”>
    </div>
    <p>If no condition will match then just put else condition as-:</p>
    <p>Users.blade.php code is written as-:</p>
    <pre><i>
    < h1> Users Page < /h1>
    @if ($user == “anil”)
    < h3> Hi {{$user}}< /h3>
    @elseif($user == “sam”)
    < h3> Hello {{$user}} < /h3>
    @else
    < h3>Unknown User < /h3>
    @endif
    </i></pre>
    <p>UsersController.php code is written as-:</p>
    <pre><i>
    < ?php
    Namespace App\Http\Controllers;
    Use Illuminate\Http\Request;
    Class UsersController extends Controller
    {
    //
    Function viewLoad()
    {
    Return View (‘users’, [‘user’=> ‘peter’]);
    }
    }
    </i></pre>
    <h5>Use “for loop” as-:</h5>
    <p>User.blade.php code written as-:</p>
    <pre><i>
    < h1>Users Page < /h1>
    @foreach($user as $user)
    < h1>{{$user}} < /h1>
    @endforeach
    </i></pre>
    <p>usersController.php is written as-:</p>
    <pre><i>
    < ?php
    Namespace App\Http\Controllers;
    Use Illuminate\Http\Request;
    Class UsersController extends Controller
    {
    //
    Function viewLoad()
    {
    $data= [‘anil’, ‘peter’, ‘locky’, ‘bruce’];
    Return view (‘users’, [user => $data]);
    }
    }
    </i></pre>
    <p>Output will be as-:</p>
    <div class=”img7″>
    <img src=”images/pic7.png” height=”200px” width=”400px”>
    </div>
    </body>

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.