Skip to content

Instantly share code, notes, and snippets.

@antonioribeiro
Last active August 29, 2021 11:55
Show Gist options
  • Save antonioribeiro/f2a22e4b665643f7614ebaeb532c605e to your computer and use it in GitHub Desktop.
Save antonioribeiro/f2a22e4b665643f7614ebaeb532c605e to your computer and use it in GitHub Desktop.
Blade::extend(function ($view) {
return preg_replace(
'/{{(\'|")(.*)(\'|")}}/',
'<?php echo e(trans($1$2$1)); ?>',
$view
);
});
// And you should be able to do tho this on your Blade templates
<h4>
{{'messages.welcome'}}
</h4>
// Instead of
<h4>
{{ trans('messages.welcome') }}
</h4>
No waste of resources, beucase this template:
<h1>{{ trans('message') }}</h1>
<h2>{{'message'}}</h2>
is compiled, once, to
<h1><?php echo e(trans('message')); ?></h1>
<h2><?php echo e(trans('message')); ?></h2>
And will stay cached until you change your view.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment