laravel:blade模板(10.27.0)
一,相关文档:
https://learnku.com/docs/laravel/10.x/blade/14852
二,创建controller和view
1,创建controller
liuhongdi@lhdpc:/data/laravel/dignews$ php artisan make:controller CommentController
INFO Controller [app/Http/Controllers/CommentController.php] created successfully.
2,创建view
liuhongdi@lhdpc:/data/laravel/dignews$ php artisan make:view CommentList
INFO View [resources/views/CommentList.blade.php] created successfully.
三,php代码:
1,app/Http/Controllers/CommentController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class CommentController extends Controller { //启用事务 public function commentList(Request $request ) { $title = "评论列表" ; $content = "请文明发言,自觉遵守相关的互联网法律法规" ; $menu = [ '原神' , '反恐精英' , '吃鸡' ]; $ls = [ [ 'name' => "张三" , "post" => "支持原神" , "reply" =>[ [ "name" => "李四" , "post" => "反对1" ], [ "name" => "王五" , "post" => "反对2" ], ], ], [ 'name' => "赵六" , "post" => "支持黎明" , "reply" =>[ [ "name" => "王老七" , "post" => "支持学友" ], [ "name" => "王大拿" , "post" => "支持刘能" ], ], ], ]; return view( 'CommentList' , [ 'title' => $title , 'content' => $content , 'menu' => $menu , 'list' => $ls , ]); } } |
2,resources/views/CommentList.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
<! DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < title >{{$title}}</ title > </ head > < body > < h1 >{{$title}}</ h1 > {{$content}} < ul > @foreach($menu as $v) < li >{{$v}}</ li > @endforeach </ ul > < ul > @foreach($list as $one) < li >< div >{{$one['name']}}:{{$one['post']}}</ div > < div > < ul > @foreach($one['reply'] as $k =>$value) < li >< div >{{$value['name']}}:{{$value['post']}}</ div > </ li > @endforeach </ ul > </ div > </ li > @endforeach </ ul > </ body > </ html > |
说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/10/22/laravel-blade-mu-ban/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
四,测试效果:
五,查看laravel框架的版本:
liuhongdi@lhdpc:/data/laravel/dignews$ php artisan --version
Laravel Framework 10.27.0