哪里放置Blade :: extend [英] Where to place Blade::extend
问题描述
我想将以下代码添加到我的laravel项目中,以支持Blade中的break和Continue语句.
I want to add the following code to my laravel project to support the break and continue statements in blade.
这是代码:
Blade::extend(function($value)
{
return preg_replace('/(\s*)@(break|continue)(\s*)/', '$1<?php $2; ?>$3', $value);
});
我不知道该放置在哪里,任何帮助将不胜感激?
I have no idea however where to place it, any help would be appreciated?
推荐答案
没有要求告诉您应该将代码放在哪里,甚至可以将其放在您的routes.php
中(当然有点混乱).您只需要确保在laravel处理页面视图时已加载它即可.
There's no requirement telling you where you should put the code, you could even put it in your routes.php
(which is a bit messy of course). You only have to make sure that it's loaded when laravel processes a page view.
在这种情况下,在某个地方创建一个新文件blade_extensions.php
并将其包含在start/global.php
中可能是一个很好的解决方案.
In this case, creating a new file blade_extensions.php
somewhere and including it in start/global.php
might be a good solution.
PS:请确保清除您已编译的视图,因为Blade仅在检测到更改时才重新编译视图,因此,如果您只是在这段代码中插针,直到您清除视图后,它才起作用.
PS: Be sure to clear out your compiled views, as Blade only recompiles the views if it detects a change, so if you've just plonked in this code it won't work until you clear out the views.
这篇关于哪里放置Blade :: extend的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!