<?php

namespace App\Models;

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

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

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

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

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