1
votes

I declared relationship between two table.. one to many... but when I tried to load data the declared relationship is not viewed in the view console..

I have this in GL

public function parent_gl_sle(){
    return $this->belongsTo('App\Sle_type','GLControlSLE_CODE','SLE_TypeCode');
} 

then this is my SL

public function child_gl_sle(){
   return $this->hasMany('App\Glcontrol','GLControlSLE_CODE','SLE_TypeCode');
}

Then, this is my controller.

$gl = Glcontrol::where('GLControlBR_CODE',$brcode)
                ->with('parent_glcontrol_br')
                ->with('parent_gl_sle')
                ->with('parent_cts')
                ->with('parent_coa')
                ->get();

But in my console parent_gl_sle is not included in the console.

enter image description here

What did I missed?

2

2 Answers

0
votes

Try something like this

$gl = Glcontrol::with(['parent_glcontrol_br','parent_gl_sle','parent_cts','parent_coa'])->where('GLControlBR_CODE',$brcode)->get(); 
0
votes
class Glcontrol extends Model
{

    public function parent_gl_sle(){
        return $this->belongsTo('App\Sle_type','foreign_key_name');
    } 

    public function child_gl_sle(){
       return $this->hasMany('App\Glcontrol','foreign_key_name');
    }
}
$data = Glcontrol::with(['parent_glcontrol_br','parent_gl_sle','parent_cts','parent_coa'])
                ->where('GLControlBR_CODE',$brcode)->get();
dd($data);