2017-08-11 90 views
1

我想發佈一個數組和一個變量來查看。這是我的變量。發佈數組和變量以查看

$ausgabeSpieltag = $saisonMaxSpieltagEins; 

這裏是我的數組和方式,就像我現在發佈它來查看。但現在我需要在 - >中添加部分變量。

$spieltagSpiel = Spielplan::where('Spieltag', '=', $ausgabeSpieltag)->where('Abgeschlossen', '=', 0)->get(); 
    foreach($spieltagSpiel as $spieltagSpielOutput){ 
     $heimName = Verein::where('V_ID', '=', $spieltagSpielOutput->Heimmannschaft)->first(); 
     $gastName = Verein::where('V_ID', '=', $spieltagSpielOutput->Gastmannschaft)->first(); 
     $resultData[$spieltagSpielOutput->Spielplan_ID] = $heimName->Name. ' - ' .$gastName->Name; 
    } 
return view('spielplan')->with('alleSpiele', $resultData); 

這裏是我的輸出刀片

<h3>Dateneingabe</h3> 

{{$ausgabeSpieltag}} 

<div class="row"> 
    <div class="col-6 col-md-4"> 
     <label for="">Spielauswahl</label> 
     <select class="form-control input-sm" name="spiele" id="spiele"> 
     @foreach($alleSpiele as $alleSpieleKey => $alleSpieleName) 
      <option value="{{ $alleSpieleKey }}"> 
       {{ $alleSpieleName }} 
      </option> 
     @endforeach 
     </select> 
    </div> 

    <div class="col-6 col-md-4"> 
     <label for="">Teamauswahl</label> 
     <select class="form-control input-sm" name="spiel" id="spiel"> 
     </select> 
    </div> 

    <div class="col-6 col-md-4"> 
     Hier kommt der Abgeschlossen Button hin 
    </div> 
</div> 

一切工作排除我{{$ ausgabeVariable}}。在變量中只有1個數字,我想在Dateneingabe之後的H3中有這個。

回答

0

你應該很容易在laravel傳遞多個變量,compact像:

$alleSpiele = $resultData; 
return view('spielplan',compact('alleSpiele','ausgabeSpieltag')); 

希望這對你的工作!

+0

我想拿出刀片{{yourVariable}},但它不會工作英寸這個怎麼做? – HansMuff

+0

@HansMuff請向您展示刀片文件{{yourVariable}} –

+0

@HansMuff您的變量意味着您在視圖文件中需要使用哪個變量。 –

1

你可以嘗試

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

,或者您可以使用緊湊

return view('spielplan')->with(compact('alleSpiele', 'variable')); 

,或者你可以把你的數據withing這樣

return view('spielplan')->with('data',['alleSpiele'=>$alleSpiele, 'variable'=>$variable]); 

數組,其中alleSpiele是數組和變量是一個變量,你已經創建

1

您可以將數據發送到查看以下陣列

return view('spielplan',['alleSpiele' => $resultData]);