如何根据表C显示表A和表B的全部数据



表A

id 名称
1 A1
2 A2
3 A3
4 A4
5 A5

您可以使用多对多关系

A::class

class A extends Model
{
public function Cs()
{
return $this->belongsToMany(C:class, 'b', 'id_table_a', 'id_table_c')->withPivot('id','name');
}
}

然后使用这个关系来获得您需要的

$as = A::with('Cs')->get();

最新更新