In order to join two tables, you need a foreign key in second table. I am considering pincode is the foreign key.
In this case, we can do that in few ways.
- Relationships
- Join Tables
Relationships
In table1 model.
public function table2()
{
return $this->hasOne('App\Table2', 'pincode');
}
In table2 model.
public function table1()
{
return $this->belongsTo('App\Table1', 'pincode');
}
Now you can access based on relationships. Ref: https://laravel.com/docs/5.4/eloquent-relationships#one-to-one
Join Tables
In this case, you can join two tables-
DB::table('table1')
->join('table2', 'table1.pincode', '=', 'table2.pincode')
->select('table1.*', 'table2.*')
->get();