2017-08-06 12 views
1

配列を作成する関数を作成しようとしています。この配列を私の見解に入れておきたい。 これは関数です。配列をビルドする方法がわかりません。 laravelからブレードに基づいて私の見解では配列PHPを作成して出力オプション値を

public function getSpielplan(){ 
     //$newdata = array (

     $spieltagSpiel = Spielplan::where('Spieltag', '=', 1)->get(); 
      foreach($spieltagSpiel as $spieltagSpielOutput){ 

       $heimName = Verein::where('V_ID', '=', $spieltagSpielOutput->Heimmannschaft)->get(); 
        foreach($heimName as $heimNameOutput){ 

         $gastName = Verein::where('V_ID', '=', $heimNameOutput->Gastmannschaft)->get(); 
          foreach($gastName as $gastNameOutput){ 

           //array ($spieltagSpielOutput->Spielplan_ID, $heimNameOutput->Name, $gastNameOutput->Name) 
          } 
        } 
      } 
     //); 
     //return view('spielplan')->with('alleSpiele', $newdata); 
    } 

、これが値で私の出力

div class="col-xs-6"> 
       label for="">Spielauswahl/label> 
       select class="form-control input-sm" name="spiele" id="spiele"> 

       @foreach($alleSpiele as $alleSpieleOutput)
  
        option value="{!! HERE MUST BE SPIELPLAN_ID [array0?]!!}">{{HERE MUST BE NAME [array1?] }}/option>
  
       @endforeach 
       /select> 
      /div> 

がSpielplan_IDしなければならないだろう、私は[0]配列の最初の列でなければならないと思いますか?オプション配列には名前配列[1]が必要です。これがうまくいくと私は何を変えなければならないのですか?

答えて

0

のこの部分を変更しようとすることができますか?私は、V_IDがVereinモデルの主キーであると考えます。私が正しければ、これらのコードに従ってください。ビューはこれを好むべき

public function getSpielplan(){ 

    $spieltagSpiel = Spielplan::where('Spieltag', '=', 1)->get(); 

    foreach($spieltagSpiel as $spieltagSpielOutput){ 

    $heimName=Verein:: where('V_ID','=',$spieltagSpielOutput->Heimmannschaft)->first(); 

    $gastName = Verein:: where('V_ID', '=', $heimNameOutput->Gastmannschaft)->first(); 

    $resultData[$spieltagSpielOutput->Spielplan_ID] = $heimName->Name. $gastName->Name; 

    } 

    return view('spielplan')->with('alleSpiele', $resultData); 

} 

ブレード、

@foreach($alleSpiele as $alleSpieleKey => $alleSpieleName) 
    <option value="{{ $alleSpieleKey }}"> 
    {{ $alleSpieleName }} 
    </option> 
@endforeach 
0

$ alleSpieleは、このオブジェクトの反復処理後のデータオブジェクトのコレクションです。オブジェクト名ではなく配列を使用する必要があります。あなたは、私はuがオプション値としてSpielplan_IDを必要と推測し、オプション名は、右heimNameとgastNameの両方と結合しなければならないコード

@foreach($alleSpiele as $alleSpieleOutput)
   
    <option value="{{ $alleSpieleOutput->SPIELPLAN_ID }}"> 
    {{$alleSpieleOutput->Name }} 
    </option>
   
@endforeach 
関連する問題