【问题标题】:Post array and variable to view [closed]发布数组和变量以查看[关闭]
【发布时间】:2018-01-19 18:22:24
【问题描述】:

我想发布一个数组和一个变量来查看。这是我的变量。

$ausgabeSpieltag = $saisonMaxSpieltagEins;

这是我的数组以及我现在发布它以查看的方式。但现在我需要在 ->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);

这是我的输出刀片

<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 中有这个。

【问题讨论】:

    标签: php arrays laravel view blade


    【解决方案1】:

    你可以试试

    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 是您创建的变量

    【讨论】:

      【解决方案2】:

      您可以发送数据到以下数组中查看

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

      【讨论】:

        【解决方案3】:

        您应该在 laravel 中使用 compact 轻松传递多个变量,例如:

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

        【讨论】:

        • 我想在刀片 {{yourVariable}} 中输出,但它不起作用。如何做到这一点?
        • @HansMuff 请向您展示您放置 {{yourVariable}} 的刀片文件
        • @HansMuff and yourVariable 表示您在视图文件中需要哪个变量。
        • 我更新了我的问题。希望你明白我的意思
        • @HansMuff 请检查我的更新答案
        猜你喜欢
        • 2012-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多