<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class MesyuaratPelesenan extends Model
{
    use HasFactory;

    protected $fillable = [
        'dt_mesyuarat', 
        'tahun',
        'bil_mesyuarat',
        'kunci_senarai'
    ];
    
    public function lesen_penjajas()
    {
        return $this->belongsToMany(LesenPenjaja::class, 'mesyuarat_pelesenan_lesen_penjajas')
                    ->withPivot(['keputusan_mesyuarat'])
                    ->withPivot(['by_law'])
                    ->withPivot(['kodlesen'])
                    ->withPivot(['kadar_lesen'])
                    ->withPivot(['kadar_sampah'])
                    ->withPivot(['kadar_sewa_petak'])
                    ->withPivot(['kadar_patil'])
                    ->with('kawasan')
                    ->withTimestamps();
    }

    public function applicationsInKawasan($kod)
    {

        return $this->lesen_penjajas()
            ->with('kawasan')
            ->whereHas('kawasan', function ($query) use ($kod) {
                $query->where('id', $kod);
            })
            ->get();
    }

}
