Files
portal-api/app/Http/Livewire/UserSettings.php
T
2025-07-24 16:18:27 +07:00

40 lines
961 B
PHP

<?php
namespace App\Http\Livewire;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Livewire\Component;
class UserSettings extends Component
{
public bool $email_marketing;
public bool $receive_deposit;
public function mount()
{
$user = auth('users')->user();
// Gán giá trị bool từ database tinyInteger
$this->email_marketing = (bool) $user->email_marketing;
$this->receive_deposit = (bool) $user->receive_deposit;
}
public function updated($propertyName)
{
$user = auth('users')->user();
// Cập nhật database với giá trị int 0 hoặc 1
$user->update([
$propertyName => $this->$propertyName ? 1 : 0,
]);
}
public function render()
{
return view('livewire.user-settings', [
'user' => auth('users')->user(), // Truyền user để hiển thị thông tin
]);
}
}