<?php 
namespace App\Models;

use CodeIgniter\Model;

class Produk_model extends Model
{
	protected $table = 'produk';
	protected $useTimestamps = true;
	protected $allowedFields = ['id_perusahaan', 'nama', 'keterangan'];

	public function get_produk($id = false)
	{
        $this->select("produk.*, perusahaan.nama as nama_perusahaan");
        $this->join('perusahaan', 'perusahaan.id = produk.id_perusahaan');
		if($id == false){
			return $this->findAll();
		}

		return $this->where(['produk.id'=>$id])->first();
	}
    
    public function get_produk_by_id_perusahaan($id_perusahaan)
    {
        return $this->where(['id_perusahaan'=>$id_perusahaan])->findAll();
    }
}