PHP code inside a Laravel 5 blade template

前端 未结 5 1097
名媛妹妹
名媛妹妹 2020-12-16 09:10

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) < da         


        
5条回答
  •  温柔的废话
    2020-12-16 09:47

    According to documentation, in Laravel 5.2 and newer you can use the following code:

    @php
    {{-- PHP code here --}}
    @endphp
    

    Alternatively, you can extend the Blade templating engine as it's described here.

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

提交回复
热议问题