I am trying to show a data in table based on column value,
I have table, col named designation_id, I would like to group the results based on the ID and show it in a particular order,
This is what I currently do to achieve the result in my blade,
My Controller,
$statemembers = StateChairman::find($id)->statemembers;
Blade
@foreach ($statemembers as $statemember)
{{$statemember->first_name}}
<br>
<h4> President </h4>
@if ($statemember->designation_id == 'P')
{{$statemember->first_name}}
@else
There are no members under the Chairman. Please add a new member under the chairman.
@endif
<h4> Vice President </h4>
@if ($statemember->designation_id == 'VP')
{{$statemember->first_name}}
@else
There are no members under the Chairman. Please add a new member under the chairman.
@endif
@endforeach
and so on,
Since the designation_id is dynamic, I would like to pick it for me dynamically.
Model,
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');
}
You can order your relations data in this way.