Post 要查看的数组和变量
Post array and variable to view
我想post一个数组和一个变量来查看。这是我的变量。
$ausgabeSpieltag = $saisonMaxSpieltagEins;
这里是我的数组以及我现在 post 查看它的方式。但是现在我需要在 ->with 部分添加变量。
$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);
这是我的输出blade
<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 中使用它。
你可以试试
return view('spielplan')->with('alleSpiele', $resultData)->with('variable',$variable);
或者您可以使用紧凑型
return view('spielplan')->with(compact('alleSpiele', 'variable'));
或者您可以使用这样的数组发送数据
return view('spielplan')->with('data',['alleSpiele'=>$alleSpiele, 'variable'=>$variable]);
其中 alleSpiele 是数组,variable 是您创建的变量
你应该在 laravel 中使用 compact
轻松传递多个变量,例如:
$alleSpiele = $resultData;
return view('spielplan',compact('alleSpiele','ausgabeSpieltag'));
您可以发送数据到以下数组查看
return view('spielplan',['alleSpiele' => $resultData]);
我想post一个数组和一个变量来查看。这是我的变量。
$ausgabeSpieltag = $saisonMaxSpieltagEins;
这里是我的数组以及我现在 post 查看它的方式。但是现在我需要在 ->with 部分添加变量。
$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);
这是我的输出blade
<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 中使用它。
你可以试试
return view('spielplan')->with('alleSpiele', $resultData)->with('variable',$variable);
或者您可以使用紧凑型
return view('spielplan')->with(compact('alleSpiele', 'variable'));
或者您可以使用这样的数组发送数据
return view('spielplan')->with('data',['alleSpiele'=>$alleSpiele, 'variable'=>$variable]);
其中 alleSpiele 是数组,variable 是您创建的变量
你应该在 laravel 中使用 compact
轻松传递多个变量,例如:
$alleSpiele = $resultData;
return view('spielplan',compact('alleSpiele','ausgabeSpieltag'));
您可以发送数据到以下数组查看
return view('spielplan',['alleSpiele' => $resultData]);