I have this table with 4 id's related to other tables.
Table List:
id table1_id table2_id table3_id table4_id
1 2 3 2 1
2 1 4 3 3
I want now to output the values related to that table's ids
id table1_name table2_name table3_name table4_name
1 jay student singer actor
2 jeane teacher drummer actress
ListController:
public function index()
{
$res = ListModel::with('table1','table2','table3','table4')->get();
$foreach($res as r){
return $r->table1_name;
}
return view('list.index',compact('res'));
}
My problem here is that the output will be null instead of jay.How can I display now the values?Please help..
list table
public function up()
{
Schema::create('list_table', function (Blueprint $table) {
$table->increments('id');
$table->string('table1_id');
$table->string('table2_id');
$table->string('table3_id');
$table->string('table4_id');
$table->timestamps();
});
}
//additional info
Table1 Model
public function list(){
return $this->belongsTo('App\ListModel');
}
List Model
public function table1(){
return $this->hasMany("App\Table1",'id','table1_id');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire