mardi 1 mai 2018

join two tables in laravel with eloquent

hay can anyone help me please..

Table 1         Table 2
Id | province       Id | Id_table1 | country
5  | Example        1  |    5      | Eng
6  | Example        2  |    6      | Laz

and this is code in my controller

use App\Models\Table1;
public function gets(){
    $data = Table1::with('yoman')->get();

}

and this is code for join in my model Table1 and Table2

class Table1 extends model{
     public function yoman()
     {
         return $this->belongsTo(Table2::class,'id');
     }
}

class Table2 extends model{

}

after i joined why the value of table2 not show i just want to join table1.Id = table2.Id_table1? sorry i'm newbie



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2rdCEdV
via IFTTT

Aucun commentaire:

Enregistrer un commentaire