Show public and local IP addresses in Livewire view
Added properties and event listener to ShowIpTest component to display both public IP (from Laravel) and local IP (from JavaScript). Updated Blade view to show both IPs and included a script to detect local IP using WebRTC and dispatch it to Livewire.
This commit is contained in:
@@ -7,10 +7,23 @@ use Illuminate\Support\Facades\Request;
|
||||
|
||||
class ShowIpTest extends Component
|
||||
{
|
||||
public $public_ip;
|
||||
public $local_ip;
|
||||
|
||||
protected $listeners = ['setLocalIP' => 'setLocalIP'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->public_ip = Request::ip();
|
||||
}
|
||||
|
||||
public function setLocalIP($data)
|
||||
{
|
||||
$this->local_ip = $data['ip'];
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
dd($ip = Request::ip());
|
||||
|
||||
return view('livewire.show-ip-test');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user