Last active
August 5, 2021 13:35
-
-
Save mrchimp/3e03220d205822f0dc000b3a89e8cd91 to your computer and use it in GitHub Desktop.
Optional Link Blade Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @php | |
| $url = $url ?? null; | |
| $class = $class ?? ''; | |
| $target = $target ?? '_self'; | |
| $rel = $target === '_blank' ? 'rel="noopener noreferrer"' : ''; | |
| @endphp | |
| @if ($url) | |
| <a href="{{ $url }}" class="{{ $class }}" {{ $rel }}> | |
| @else | |
| <span class="{{ $class }}"> | |
| @endif | |
| {{ $slot }} | |
| @if ($url) | |
| </a> | |
| @else | |
| </span> | |
| @endif |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If url is provided then the slot will be wrapped in an
a, otherwise aspan.This would be better as an
x-style blade component as we can more easily control attributes.