Langkah 5 dari 11
Membuat ProductModel
Buat app/Models/ProductModel.php:
<?php
namespace App\Models;
use CodeIgniter\Model;
class ProductModel extends Model
{
protected $table = 'products';
protected $primaryKey = 'id';
protected $returnType = 'array';
protected $protectFields = true;
protected $allowedFields = ['sku', 'name', 'price', 'stock', 'description'];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
}
$allowedFields adalah daftar kolom yang boleh diisi melalui Model. Jangan memasukkan kolom sensitif atau kolom yang tidak boleh dikendalikan pengguna.
