<?php
use Illuminate\Support\Str;
$fkClass = $references[0];
$fkKey = $references[1];
$fkLabel = $references[2];

$listes =  $fkClass::select('*')->get();

$refModel = new $fkClass();
$refKey = $refModel->getPrimaryKey();

?>
<div class="{{$div_class}}">
    <div class="form-group">
        <label for="{{$fkKey}}" class="control-label">{{$title}}</label>
        <select  class="form-control select2" name="{{$fkKey}}" id="{{$fkKey}}">
            <option value="">*Choisir</option>
            @foreach($listes as $liste)
                <?php
                 if(Str::endsWith($fkLabel, '()')){
                     $func = Str::substr($fkLabel, 0, Str::length($fkLabel)-2);
                     $text = $liste->$func();
                 }else{
                    $text = $liste->$fkLabel;
                 }
                ?>
                <option @if(old($fkKey,$model->$fkKey)==$liste->$refKey) selected @endif value="{{$liste->$refKey}}">{{$text}}</option>
            @endforeach
        </select>
    </div>
</div>


