Blogger Information
Blog 28
fans 0
comment 0
visits 25657
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
blade模板、laravel中间件
,多思曩惜,
Original
801 people have browsed it

blade模板

  1. <!--原声-->
  2. <?php if($myage>=18){?>
  3. <div>已成年<?php echo $name; ?></div>
  4. <?php }else { ?>
  5. <div>为成年</div>
  6. <?php } ?>
  7. <!-- blade模板引擎 -->
  8. @if($myage >=18)
  9. <div>已成年{!!$name!!}</div>
  10. @else
  11. <div>未成年</div>
  12. @endif

blade模板中foreachforwhile语法

  1. <tbody>
  2. @foreach($res as $val)
  3. <tr>
  4. <td>{{$val['id']}}</td>
  5. <td>{{$val['username']}}</td>
  6. </tr>
  7. @endforeach
  8. </tbody>
  9. <tbody>
  10. @for($i=0;$i<count($res);$i++)
  11. <tr>
  12. <td>{{$res[$i]['id']}}</td>
  13. <td>{{$res[$i]['username']}}</td>
  14. </tr>
  15. @endfor
  16. </tbody>
  17. <tbody>
  18. @while($val =array_pop($res))
  19. <tr>
  20. <td>{{$val['id']}}</td>
  21. <td>{{$val['username']}}</td>
  22. </tr>
  23. @endwhile
  24. </tbody>

中间件

  • 创建中间件
  • 使用artisan命令创建中间件
    php artisan make:middleware Mymiddle
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. class Mymiddle
  5. {
  6. /**
  7. * Handle an incoming request.
  8. *
  9. * @param \Illuminate\Http\Request $request
  10. * @param \Closure $next
  11. * @return mixed
  12. */
  13. public function handle($request, Closure $next)
  14. {
  15. // echo "中间件";
  16. // echo $request;
  17. return $next($request);
  18. }
  19. }
  • 注册中间件

  • 在app/http/kemel.php中protected $routeMiddleware属性中定义

  1. // 自定义中间件
  2. 'mymiddle'=>\App\Http\Middleware\Mymiddle::class,
  • 使用中间件

  • 在路由中使用中间件Route::get('/myblade','Home@myblade')->middleware('mymiddle');

总结

  • 了解了blade模板语法,学会使用部分语法。
  • 了解中间件的使用原理和如何使用
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:blade语法, 与tp中的smarty风格区别 较大, 但更简洁
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!