<?php

namespace App\Models;

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

class SubAccount3 extends Model
{
    use HasFactory;
    protected $table = "sub_accounts_3";
    protected $fillable = ['account_code','sub_name', 'parent_id', 'account_type'];

    public function subAccount2()
    {
        return $this->belongsTo(SubAccount2::class, 'parent_id');
    }

    public function subAccounts4()
    {
        return $this->hasMany(SubAccount4::class, 'parent_id');
    }

    public function mainAccount()
    {
        return $this->hasOneThrough(MainAccount::class, SubAccount2::class, 'id', 'id', 'parent_id', 'parent_id');
    }
}
