oh sorry!
the interessant part of user.php :
public function cfds()
{
return $this->belongsTo('App\Models\Cfd', 'id_cfds');
}
public static function getListFormateurEM(){
User::whereHas('cfds', function($query) {
$query->where('isEM', 1);
})->with('cfds')
->where('isFormateur', true)
->where('isChefdeCours', false)
->where('isExterieur', false)->get();
}
public static function getRetardFondDeSalleEM(){
$sql = User::getListFormateurEM()
->WhereRaw('(((`date_controle` is null AND (date_mutation < DATE_SUB( curdate() , INTERVAL 6 MONTH))) or (date_prev_controle < curdate()) or (date_controle is null and date_mutation is null)) AND (date_depart IS NULL OR curdate() < date_depart ))');
return $sql;
}
the interessant part of view :
@foreach ($nbFormateurSPenRetard as $unItem)
<tr class="danger">
<td class="text-primary text-center"><strong>{!!$unItem->grades->trigramme!!} {!!$unItem->nom!!} {!!$unItem->prenom!!}</strong></td>
<td class="text-primary text-center">
@if (empty(substr($unItem->cfds->clair,4)))
<strong>EMB</strong>
@else
<strong>{!! substr($unItem->cfds->clair,4) !!}</strong>
@endif
</td>
<td class="text-primary text-center">
{!! $unItem->date_controle !!}
</td>
<td class="text-primary text-center">
{!! $unItem->date_prev_controle !!}
</td>
<td class="text-primary text-center"><strong>
@if ($unItem->nbComm!=0)
<span class="badge">{!! $unItem->nbComm !!}</span>
@endif
</strong>
</td>
<td class="text-center">
<a href="{!!URL::to('fondDeSalle/'.$unItem->id.'/edit')!!}" class='btn btn-success btn-xs' title="Contrôler">
<i class="fa fa-edit fa-lg"></i>
</a>
</td>
</tr>
@endforeach
the line of the repository :
$nbFormateurSPenRetard = User::getRetardFondDeSalleEM()->orderBy('date_controle','asc')->get();