ErrorException未定义的变量

时间:2017-11-02 13:46:06

标签: laravel-5.4

我有像ErrorException这样的按摩错误 未定义的变量:posts(查看:C:\ xampp \ htdocs \ TA \ resources \ views \ petani \ index.blade.php)。我该如何解决?

控制器:

public function index(){

$post = Desa::all();    
return view('petani.index',compact ('desas')); 
}

路线:     Route::get('petani', 'BiodataController@index'); 指数:

    <?php
        $no = 1;
        ?>
         @foreach ($posts as $post) 
    <td>{{$no++}}</td>
    <td>{{$post->nama}}</td>

    <td>
        <button type="button" class="btn"><a href="{{ URL::to('coba/test/'.$post->id.'/edit') }}" >Edit</a></button>
         {{ Form::open(['url' => 'coba/test/'.$post->id, 'method' => 'DELETE']) }}
           {{ Form::button('delete', ['type' => 'submit', 'class' => 'btn']) }}
        {{ Form::close() }}

    </td>

  </tr>
   @endforeach

1 个答案:

答案 0 :(得分:1)

而不是compact('desas'),输入['posts' => $post],你就可以了