Skip to content

Instantly share code, notes, and snippets.

@Kehet
Last active March 28, 2021 11:53
Show Gist options
  • Save Kehet/b44d0e03dd48539b1544708473781480 to your computer and use it in GitHub Desktop.
Save Kehet/b44d0e03dd48539b1544708473781480 to your computer and use it in GitHub Desktop.
laravel blade tag for formatting dates. place this into app/Providers/AppServiceProvider.php::boot
<?php
Blade::directive('fancytime', function ($time) {
return "<abbr title=\"<?php echo " . $time . "->format('d.m.Y H:i:s'); ?>\">" .
"<time datetime=\"<?php echo " . $time . "->toIso8601String(); ?>\">" .
"<?php echo " . $time . "->diffForHumans(); ?>" .
"</time>" .
"</abbr>";
});
@props(['time'])
<abbr title="{{ $time->format('d.m.Y H:i:s') }}">
<time datetime="{{ $time->toIso8601String() }}">
{{ $time->diffForHumans() }}
</time>
</abbr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment