Level 39
Put the source file in public directory and use it.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
this is the php code and i want to write this code in model Laravel
<?php
class devicesModel {
private $result;
protected $conn;
protected $db;
function __construct() {
$this->db = new Config();
$this->conn = $this->db->getConnection();
}
function verifyIfDeviceNumberValid($devicenumber) {
try {
$sqlQuery = "select id from devices where Devicenumber=$devicenumber";
$stmt = $this->conn->prepare($sqlQuery);
$stmt->execute();
$row2 = $stmt->fetch();
if (!empty($row2['id'])) {
return true;
}
} catch (PDOException $ex) {
$this->result = " Process failed unexpectedly";
}
return false;
}
function saveDeviceDetails($cartitems) {
try {
for ($i = 0; $i < count($_SESSION['verified']); $i++) {
$sqlQuery = "INSERT INTO `cartitems`(`devicenumber`) VALUES(" . $_SESSION['verified'][$i] . ")";
$stmt = $this->conn->prepare($sqlQuery);
$stmt->execute();
}
return TRUE;
} catch (PDOException $ex) {
$this->result = " Process failed unexpectedly".$ex->getMessage();
}
return false;
}
//Accesors and Mutators
function getResult() {
return $this->result;
}
function setResult($result) {
$this->result = $result;
}
}
Please or to participate in this conversation.