【发布时间】:2018-12-24 17:17:24
【问题描述】:
错误出现在视图上
我的 $audio 变量没有定义。
我想使用 foreach 循环显示数据库中的所有内容。
我尝试基于 laravel 文档 https://laravel.com/docs/5.7/pagination#basic-usage 上的分页
我的控制器在下面:
use Illuminate\Http\Request;
use App\Audio_lectures;
use Illuminate\Support\Facades\DB;
public function index(){
$audio = DB::table('audio_lectures')->latest()->paginate();
return view('welcome', ['audio_lectures' => $audio]);
}
欢迎视图如下:
<div class="container">
<div class="row">
<table class="table table-dark">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Subject</th>
<th scope="col">Date Added</th>
<th scope="col">Download</th>
</tr>
</thead>
<tbody>
@foreach ($audio as $audio_lectures)
<tr>
<th scope="row">{{$audio_lectures->id}}</th>
<td>{{$audio_lectures->subject}}</td>
<td>{{$audio_lectures->created_at}}</td>
<td><a href="{{$audio_lectures->filelink}}" class="btn btn-outline-light btn-sm">Download</a></td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
我的路由 web.php 如下:
Route::get('/','Audio_lecturesController@index');
我希望将数据库中的所有音频讲座显示到我的视图中。
【问题讨论】: