Laravel:未定义的变量:anmeldung(查看:/Users/rotschaedl/nost1/resources/views/uebersicht.blade.php)

时间:2019-03-05 12:52:59

标签: php laravel

这是我在控制器中的代码。

public static function allean(){
        $anmeldung=DB::table('anmeldung')->select('*')->get();
        echo $anmeldung;
        return view('uebersicht', compact('anmeldung'));
}

这是视图中的m代码。

<?php
MainController::allean();
?>    

@if(null!==session('lehrer'))
            @foreach($anmeldung as $row)
                <tr>
                    <th scope="row" class="central">1</th>
                    <td class="central"> $row['vorname']}} {{$row['nachname']}} </td>
                    <td class="central">0000000</td>
                    <td class="central">AAA</td>
                    <td class="central">ok</td>
                    <td class="central">aaaaa</td>
                    <td class="central">Mathe</td>
                    <td class="central">ooooo</td>
                    <td class="central">asd </td>
                    <td class="central">12.10.2018</td>
                    <td class="central">{{Form::checkbox('', '')}}</td>
                    <td class="central">{{Form::checkbox('', '')}}</td>
                </tr>
            @endforeach
        @endif

然后我在网站上收到该错误。

  

未定义变量:anmeldung(查看:   /Users/user/project/resources/views/uebersicht.blade.php)

4 个答案:

答案 0 :(得分:1)

尝试使用键值对:

public static function allean(){
        $anmeldung=DB::table('anmeldung')->select('*')->get();
        echo $anmeldung;
        return view('uebersicht', ['anmeldung'=>$anmeldung]);
}

答案 1 :(得分:0)

尝试一下!

如果条件在foreach @if(!empty($anmeldung))@endif之前添加

@if(null!==session('lehrer'))
            @if(!empty($anmeldung))
            @foreach($anmeldung as $row)
                <tr>
                    <th scope="row" class="central">1</th>
                    <td class="central"> $row['vorname']}} {{$row['nachname']}} </td>
                    <td class="central">0000000</td>
                    <td class="central">AAA</td>
                    <td class="central">ok</td>
                    <td class="central">aaaaa</td>
                    <td class="central">Mathe</td>
                    <td class="central">ooooo</td>
                    <td class="central">asd </td>
                    <td class="central">12.10.2018</td>
                    <td class="central">{{Form::checkbox('', '')}}</td>
                    <td class="central">{{Form::checkbox('', '')}}</td>
                </tr>
            @endforeach
@endif
        @endif

答案 2 :(得分:0)

您错过了{{附近的<td class="central"> $row['vorname']}} {{$row['nachname']}} </td>

您可以尝试以下代码:

public static function allean(){
        $anmeldung=DB::table('anmeldung')->select('*')->get();
        //var_dump($anmeldung);
        return View::make('uebersicht')->with(compact('anmeldung'));
}

您应该这样修改视图:

@if(null!==session('lehrer'))
        @foreach($anmeldung as $row)
            <tr>
                <th scope="row" class="central">1</th>
                <td class="central"> {{ $row['vorname']}} {{$row['nachname']}} </td>
                <td class="central">0000000</td>
                <td class="central">AAA</td>
                <td class="central">ok</td>
                <td class="central">aaaaa</td>
                <td class="central">Mathe</td>
                <td class="central">ooooo</td>
                <td class="central">asd </td>
                <td class="central">12.10.2018</td>
                <td class="central">{{Form::checkbox('', '')}}</td>
                <td class="central">{{Form::checkbox('', '')}}</td>
            </tr>
        @endforeach
    @endif

答案 3 :(得分:-1)

您应该这样修改视图:

控制器

public static function allean(){
        $anmeldung = DB::table('anmeldung')->select('*')->get();
        return $anmeldung;
}

查看

@if(null!==session('lehrer'))
    @foreach(App\MainController::allean() as $row)
        <tr>
            <th scope="row" class="central">1</th>
            <td class="central"> $row['vorname']}} {{$row['nachname']}} </td>
            <td class="central">0000000</td>
            <td class="central">AAA</td>
            <td class="central">ok</td>
            <td class="central">aaaaa</td>
            <td class="central">Mathe</td>
            <td class="central">ooooo</td>
            <td class="central">asd </td>
            <td class="central">12.10.2018</td>
            <td class="central">{{Form::checkbox('', '')}}</td>
            <td class="central">{{Form::checkbox('', '')}}</td>
        </tr>
    @endforeach
@endif