Laravel 5.1:我在 BladeServiceProvider 中定义了一些自定义指令(下面的示例)。现在我想在视图模板之外使用它们来格式化字符串(我正在自定义 ExportService 类中使用 PHPExcel 编写一个 EXCEL 文件)。是否可以重用我的指令?
Blade::directive('appFormatDate', function($expression) {
return "<?php
if (!is_null($expression)) {
echo date(\Config::get('custom.dateformat'), strtotime($expression));
}
else {
echo '-';
}
?>";
});