Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

You should have two models tableA and TableB, since the tableB key is included with tableA that means the tableA belongs to tableB . If relation is one to one use haseOne if one to many use hasMany

class TableB extends Eloquent {  
    ...
    public function tableA(){

        return $this->hasOne('TableA');
    }
    ...
}
class TableA extends Eloquent {  
    ...
    public function tableB(){
        return $this->belongsTo('TableB');
    }
    ...
}
Last updated 2 years ago.
0

Ya, I get that. But that works with 1 column in each table right? Here I have 1 column in TableB that is related to 2 columns in TableA.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.