File: //proc/self/cwd/Livewire/Profile/SetPin.php
<?php
namespace App\Livewire\Profile;
use Livewire\Component;
use App\Services\ApiEndpoints;
use App\Services\DeviceService;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Session;
class SetPin extends Component
{
public $pin;
public $device_name;
public $user_id;
public $showPin;
protected $rules = [
"pin" => "required|digits:4",
];
public function mount(DeviceService $deviceService)
{
try {
$this->device_name = $deviceService->getDeviceName();
$user = Session::get('user');
$this->user_id = $user['id'];
} catch (\Exception $e) {
$this->addError('pin', $e->getMessage());
Session::flash('error', $e->getMessage());
}
}
public function setPin()
{
$this->validate();
try {
$response = Http::post(ApiEndpoints::setPin(), [
'pin' => $this->pin,
'device_name' => $this->device_name,
'user_id' => $this->user_id,
]);
if ($response->successful()) {
$info = $response->json(['message']);
// Retrieve the current session data
$userData = Session::get('user');
// Update the is_pin value
$userData['is_pin'] = 1;
// Save the updated data back into the session
Session::put('user', $userData);
Session::flash('success', $info);
$this->addError('response', $info);
} else {
$info = $response->json(['message']);
$this->addError('pin', $info);
Session::flash('error', $info);
}
} catch (\Throwable $e) {
$info = $e->getMessage();
Session::flash('error', $info);
Log::error($e->getMessage());
$this->addError('email', $info);
}
}
public function render()
{
return view('livewire.profile.set-pin');
}
}