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 '-';
}
?>";
});
发布于 2018-09-07 13:48:44
该BladeCompiler
有一个compileString
方法,它允许您使用的意见外刀片指令。:)
所以,你可以做这样的事情:
$timestamp = '2015-11-10 17:41:53';
$result = Blade::compileString('@appFormatDate($timestamp)');
https://stackoverflow.com/questions/-100002582
复制相似问题