这是我的 Controller :
public function create(){
$categories =DB::select('select Code from ItemCategory');
return view('item')->with('ItemCategory', $categories);
我的 View 文件:
<div class="form-group">
{!! Form::label('Link Category') !!}<br />
{!! Form::select('categories',
(['0' => 'Select a Category'] + $categories),
null,
['class' => 'form-control']) !!}
</div>
但是当我运行这个时,我收到以下错误
InvalidArgumentException in FileViewFinder.php line 137: View [item] not found.
PS:
我的数据库表:
+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| ID | int(11) | NO | PRI | NULL | |
| Code | varchar(45) | NO | | NULL | |
| ItemCategotyID | int(11) | NO | | NULL | |
| ItemLevelID | int(11) | NO | | NULL | |
| isActive | varchar(45) | YES | | NULL | |
+----------------+-------------+------+-----+---------+-------+
我已经尝试过this例子。这里有什么错误呢?如何使用 MySQL 表获取下拉列表的值?
最佳答案
这似乎不是您从数据库检索的内容的问题,而是您引用的 View 的问题
return view('item')->...
View “item”可能不在您认为的位置。引用自 Laravel 文档:
Of course, views may also be nested within sub-directories of the resources/views directory. "Dot" notation may be used to reference nested views. For example, if your view is stored at resources/views/admin/profile.php, you may reference it like so:
return view('admin.profile', $data);
关于数据库查询的旁注,您可以尝试使用集合来使处理 View 时的生活更轻松。
关于php - 使用 Laravel-5 的下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36353506/