Last active
July 28, 2023 14:13
-
-
Save radermacher/28c223cb350ba3d0659b1a125e358f5c to your computer and use it in GitHub Desktop.
NativePHP External Link Livewire Component #nativephp #livewire
This file contains 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 | |
namespace App\Http\Livewire; | |
use Livewire\Component; | |
use Native\Laravel\Facades\Shell; | |
class ExternalLink extends Component | |
{ | |
public $url; | |
public $class; | |
public $label; | |
public function render(): string | |
{ | |
return <<<'blade' | |
<a | |
href="{{ $this->url }}" | |
wire:click.prevent="openUrl" | |
class="{{ $class }}" | |
> | |
{!! $label !!} | |
</a> | |
blade; | |
} | |
public function openUrl(): void | |
{ | |
Shell::openExternal($this->url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or you can use JavaScript directly in your view to open an external link in the user's default browser:
This solution based on Mark Beech comment:
→ https://twitter.com/JayBird1979/status/1684919646925795330