Hi, it seems like the identifier test
is reserved in some way, as it always return blank. Also, Laravel comes with some helpers for Blade Extensions which makes the job abit easier. See Extending Blade.
Eg:
<?php
Blade::extend(function($view, $compiler)
{
$pattern = $compiler->createMatcher('totime');
return preg_replace($pattern, '$1<?php echo strtotime($2); ?>', $view);
});
Would return the time whenever using @totime('now')
.
Thanks alot, works for me in this case... but whats the best way to implement kind of buisnesslogic to Blade::extend()?
This seems not so elegant to me as it may could be.... ;-)
<?php
Blade::extend(function($view, $compiler) {
$pattern = $compiler->createMatcher("weCheck");
return preg_replace($pattern, '$1<?php '
. '$we_timestamp = strtotime($2); '
. '$we_expired = strtotime("+1 day", $we_timestamp);'
. 'if($we_expired < time()){'
. 'echo "red";'
. '}'
. '?>', $view);
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community