- Hands-On Full Stack Web Development with Angular 6 and Laravel 5
- Fernando Monteiro
- 264字
- 2021-07-23 19:18:47
Creating the Blade template engine
Now, it's time to create another view component. This time, we will use the Blade template engine to show some records from our database. Let's look at what the official documentation says about Blade:
Blade is the simple, yet powerful, templating engine provided with Laravel. Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views. All Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application.
Now, it's time to see this behavior in action:
- Go back to the code editor and create another folder inside resources/views, called bands.
- Create a file, show.blade.php, inside resources/views/bands, and place the following code in it:
<h1>Band {{ $band->id }}</h1>
<ul>
<li>band: {{ $band->name }}</li>
<li>description: {{ $band->description }}</li>
</ul>
You can find out more about Blade at https://laravel.com/docs/5.2/blade.
- Open your browser to http://localhost:8081/bands/1. You will see the template in action, with results similar to the following:

View of the template engine
Note that here, we are using the Blade template engine to show a record from our database. Now, let's create another view to render all of the records.
- Create another file, called index.blade.php, inside resources/views/bands, and place the following code in it:
@foreach ($bands as $band)
<h1>Band id: {{ $band->id }}</h1>
<h2>Band name: {{ $band->name }}</h2>
<p>Band Description: {{ $band->description }}</p>
@endforeach
- Go back to your browser and visit http://localhost:8081/bands/, where you will see a result similar to the following:

View template engine
推薦閱讀
- EJB 3.1從入門到精通
- 解析QUIC/HTTP3:未來互聯網的基石
- RCNP實驗指南:構建高級的路由互聯網絡(BARI)
- INSTANT PhpStorm Starter
- Hands-On Industrial Internet of Things
- 物聯網概論(第2版)
- 互聯網安全的40個智慧洞見:2015年中國互聯網安全大會文集
- Wireshark網絡分析就這么簡單
- 城域網與廣域網(第2版)
- 數字調制解調技術的MATLAB與FPGA實現:Altera/Verilog版(第2版)
- Microservice Patterns and Best Practices
- 網絡空間全球治理觀察
- 移動互聯網新思維
- 現場綜合化網絡運營與維護:運營商數字化轉型技術與實踐
- 世界互聯網發展報告2021