我必须在 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 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Laravel Eloquent Union 查询Laravel Eloquent Union query(Laravel Eloquent Union 查询)
覆盖 Laravel 5 辅助函数Overwrite laravel 5 helper function(覆盖 Laravel 5 辅助函数)
laravel querybuilder 如何在 where 函数中使用 likelaravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函数中使用 like)
响应内容必须是实现 __toString()、“boolean"和“The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(响应内容必须是实现 __toS
Laravel 5 的角色,如何只允许管理员访问某些根Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允许管理员访问某些根)
Laravel Auth - 使用 md5 而不是集成的 Hash::make()Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())