ria/app/Models/FactoryMachineModel.php
2024-12-19 16:05:39 +05:30

69 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use CodeIgniter\Model;
class FactoryMachineModel extends Model
{
// The table associated with this model
protected $table = 't_factoryMachineMaster';
// Primary key of the table
protected $primaryKey = 'id';
// Return type (you can use 'array' or 'object')
protected $returnType = 'array';
// Fields that are allowed to be inserted or updated
protected $allowedFields = ['machine_name', 'machine_type', 'energy_type', 'is_active', 'created_at', 'updated_at'];
// Enable automatic timestamps
protected $useTimestamps = true;
// Define custom timestamps columns, if necessary (optional)
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
// Validation rules (optional)
protected $validationRules = [
'machine_name' => 'required|max_length[255]',
'machine_type' => 'required|max_length[255]',
'energy_type' => 'required|max_length[255]',
];
// Validation messages (optional)
protected $validationMessages = [];
// Skip validation (set to true to skip validation rules)
protected $skipValidation = false;
public function checkMachineName($machineId,$machineName){
$builder = $this->db->table('t_factoryMachineMaster');
if(!empty($machineId)){
$builder = $builder->where('id !=' , $machineId);
}
$builder = $builder->where('REPLACE(machine_name, " ", "") ',$machineName);
$query = $builder->get();
if ($query->getNumRows() > 0) {
return $query->getResultArray();
} else {
return [];
}
}
}