我有两位主席和成员。
主席桌
id | first_name | from | to | row_status
-----------------------------------------
1 | old Chairman | 3-2017 | 5-2018 | 0
2 | Chairman | 6-2018 | 4-2018 | 1
会员表
id | chairman_id | | Name | role | row_status
-------------------------------------------
1 | 1 | president | P | 0
2 | 1 | vice president | VP | 0
3 | 2 | president | p | 1
4 | 2 | vice president | VP | 1
我试图根据主席的从-到期间来显示活跃的(row_Status = 1)主席和成员
如果有多个主席,我不确定如何显示结果。
我当前正在如下显示结果,
刀片页面
@foreach ($statechairmans as $statechairman)
<li>
{{$statechairman -> first_name}}
</li>
<li> {{ $statechairman->statemembers->first_name }} </li>
@endforeach
型号:
State Chairman
public function statemembers(){
return $this->belongsTo('App\Statemembers', 'id','chairman_id');
}
State Members
public function statechairman(){
return $this->hasMany('App\Statechairman');
}
我能够按预期查看结果,但是我不确定如何根据角色来处理数据。
如何根据用户的角色显示用户,并在有更多主席的情况下访问多个主席。
例如
Active
Chairman -> President -> Vice-President -> etc,
Old Chairman - 3-2017 | 5-2018
Chairman -> President -> Vice-President -> etc,
答案 0 :(得分:1)
@foreach ($statechairmans as $statechairman)
<li>
{{$statechairman -> first_name}}
</li>
<li> {{ $statechairman->statemembers->first_name }} </li>
@if($statechairman->row_status == 1)
from : {{ $statechairman->from}}
to: {{ $statechairman->to}}
@endif
@endforeach
希望它会有所帮助:)