PHP code inside a Laravel 5 blade template(Laravel 5 刀片模板中的 PHP 代码)
问题描述
我必须在 Laravel 5 刀片模板中放置一些 PHP 代码.如下图
I have to place some PHP code inside a Laravel 5 blade template. Like below
@foreach ($farmer->tasks as $task)
@if ($task->pivot->due_at) < date(now))
$style = 'alert alert-danger';
@elseif ($task->pivot->due_at) > date(now))
$style = 'alert alert-success';
@else
$style = '';
@endif
@endforeach
将 PHP 代码放入 Laravel 5 刀片模板的实际过程是什么?
What is the actual procedure to place PHP code inside a Laravel 5 blade template?
推荐答案
根据文档,在 Laravel 5.2 及更新版本中,您可以使用以下代码:
According to documentation, in Laravel 5.2 and newer you can use the following code:
@php
{{-- PHP code here --}}
@endphp
或者,您可以扩展 Blade 模板引擎,如此处所述.
Alternatively, you can extend the Blade templating engine as it's described here.
如果以上两种解决方案都不合适,那么您会被Armen 和 作者:贡萨洛.
If neither of the above solutions is suitable, you are stuck with the answers given by Armen and by Gonzalo.
这篇关于Laravel 5 刀片模板中的 PHP 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 5 刀片模板中的 PHP 代码


基础教程推荐
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的PDF导出 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- php中的foreach复选框POST 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01