Add Livewire component to display and save user IP
Introduces ShowSavingIp Livewire component to fetch, display, and save the authenticated user's IP address. Integrates the component into the navigation layout and comments out the unused /ip-test route.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ShowSavingIp extends Component
|
||||
{
|
||||
public $ip_address;
|
||||
|
||||
protected $listeners = ['setIpAddress'];
|
||||
|
||||
public function setIpAddress($ip)
|
||||
{
|
||||
$this->ip_address = $ip;
|
||||
|
||||
$user = Auth::user();
|
||||
if ($user) {
|
||||
$user->ip_address = $ip;
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.show-saving-ip');
|
||||
}
|
||||
}
|
||||
@@ -237,8 +237,10 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<livewire:show-saving-ip />
|
||||
|
||||
<!-- Logout -->
|
||||
<div class="pt-6">
|
||||
<div>
|
||||
<form method="POST" action="{{ route('logout') }}">
|
||||
@csrf
|
||||
<button type="submit" class="w-full text-left py-2 px-3 rounded flex items-center justify-start gap-2 bg-red-600 text-white hover:bg-red-700">
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<div
|
||||
x-data="{
|
||||
getIp() {
|
||||
fetch('https://api.ipify.org/?format=json')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
$wire.emit('setIpAddress', data.ip);
|
||||
})
|
||||
.catch(err => console.error('Error obteniendo IP:', err));
|
||||
}
|
||||
}"
|
||||
x-init="getIp()"
|
||||
wire:poll.visible.delay.600000ms
|
||||
class="py-4"
|
||||
>
|
||||
<p class="text-sm text-gray-600">
|
||||
@if($ip_address)
|
||||
Tu IP actual: <strong>{{ $ip_address }}</strong>
|
||||
@else
|
||||
Obteniendo IP...
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
+1
-1
@@ -75,7 +75,7 @@ Route::middleware(["auth", "solo_usuario_administrador"])->group(function () {
|
||||
|
||||
Route::post('/registrar-accion-compra', [MenuController::class, 'click_compra'])->name('click_compra');
|
||||
|
||||
Route::get('/ip-test', [MenuController::class, 'ip_test'])->name('ip');
|
||||
// Route::get('/ip-test', [MenuController::class, 'ip_test'])->name('ip');
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user