我正在尝试输出订单结果以及将记录命名为相应的ID
我想要实现的目标,
Chairman |
|
President - Heading
- member name
Vice President - Heading
- member name
我有一个董事长,其下属根据指定ID进行划分
为此,我创建了3table, 议长
id | first_name | from | to
1 | Chairman | 2019 | 2020
州议员
id | first_name | chairman_id | designation_id
1 | Member 1 | 1 | P (inherted from designation_code of statedesignation)
1 | Member 2 | 1 | VP (inherted from designation_code of statedesignation)
州名称
id | designation_code | designation_name | designation_desc
1 | P | President | President Description.
1 | VP | Vice President | President Description.
我想显示成员列表及其后缀:
我尝试订购桌子,但是我无法为相应的会员输入名称,
我的控制人将会员国带入董事长
$statemembers = StateChairman::find($id)->statemembers()->orderBy('designation_id')->get();
dd($statemembers);
But when I try this
$statedesignation = Statemembers::find($id)->statedesignations()->get();
dd($statemembers);
I am only getting Designation **President** since find($id) brings up only 1 or corresponding id
型号:
class Statechairman extends Model
{
public function statemembers(){
return $this->hasMany('App\Statemembers','chairman_id','id');
}
}
class Statemembers extends Model
{
public function statechairman(){
return $this->belongsTo('App\Statechairman','chairman_id','id');
}
public function statemembers(){
return $this->hasMany('App\Statemembers');
}
参考: 这是post
的延续