Laravel 5 Blade Template中的PHP代码 [英] PHP code inside Laravel 5 Blade Template

查看:71
本文介绍了Laravel 5 Blade Template中的PHP代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在Laravel 5 Blade Template中放置一些PHP代码.像下面一样

I have to place some PHP code inside 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 Blade Template中的实际过程是什么?

Which is the actual procedure to place PHP code inside 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和@Gonzalo给出的答案所困扰

If neither of the above solutions is suitable, you are stuck with the answers given by @Armen and @Gonzalo

这篇关于Laravel 5 Blade Template中的PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆