- 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
推薦閱讀
- 微商之道
- SOA用戶指南
- SEO 20日
- TCP/IP入門經(jīng)典(第5版)
- PLC、現(xiàn)場總線及工業(yè)網(wǎng)絡(luò)實(shí)用技術(shù)速成
- 物聯(lián)網(wǎng)時(shí)代
- CCNP TSHOOT(642-832)認(rèn)證考試指南
- SAE原理與網(wǎng)絡(luò)規(guī)劃
- 一本書讀懂物聯(lián)網(wǎng)
- 局域網(wǎng)組成實(shí)踐
- 云計(jì)算技術(shù)與標(biāo)準(zhǔn)化
- 新媒體交互藝術(shù)
- 區(qū)塊鏈社區(qū)運(yùn)營手冊
- 黑客與反黑工具使用詳解
- 企業(yè)網(wǎng)絡(luò)組建與維護(hù)項(xiàng)目式教程