【发布时间】:2017-12-01 17:05:31
【问题描述】:
我一直试图在索引页面中列出一个包含数据库数据的下拉列表。我创建了一个模型并在控制器中进行了一些更改以在我的视图页面中显示它,但是在控制器中进行任何更改都会在控制台中显示一个空白页面,其中包含 500 内部服务器错误。请帮我解决这个问题。
表名:walker_type
路线:
Route::get('/', 'WebController@index');
型号:ProviderType.php:
<?php
class ProviderType extends Eloquent {
protected $table = 'walker_type';
}
控制器:WebController.php
public function index() {
$walkerTypeList = ProviderType::all();
return view('website.index')->with(['walkerTypeList' => $walkerTypeList]);
}
查看:index.php
@foreach ($walkerTypeList as $car)
<option data-icon="glyphicon-road" value="{{ $car->name }}"> {{ $car->name }} </option>
@endforeach
【问题讨论】:
-
请检查您的错误日志是什么导致了 500 错误。如果您在开发人员机器上运行代码,您还可以启用调试以显示错误消息而不是 500 页面。只是快速浏览一下您的代码 sn-ps,我最初的假设是您缺少 WalkerType 中 SoftDeletingTrait 的 use 语句,但最好查看错误消息以确定。
-
你试过
with('walkerTypeList', $walkerTypeList);吗? -
dd($walkerTypeList)在您的控制器中返回视图之前,看看它是否首先被填充。 -
@dbrumann 我发现了我的一个错误。已经有一个用于相同表名 ProviderType 的模型。所以我只是在控制器的索引函数中将模型名称替换为相同的名称。然后调试它显示了结果。但是我仍然无法将变量传递给查看。
标签: laravel