本文介紹了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 代碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!