php - 使用 Laravel-5 的下拉菜单

标签 php mysql laravel-5

这是我的 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/

相关文章:

javascript - Laravel-Ajax : multiple inputs in 1 form

php - 在准备好的语句中执行不返回任何内容

php - fatal error : Allowed memory size of 25165824 bytes exhausted

Mysql 多个 ORDER BY 和 UNION

sql - MySQL - 从具有相同结构但数据不同的多个表中选择数据

mysql - Laravel:hasMany 关系 + where 条件失败

php - Laravel - DOMDocument::loadXML(): 开始和结束标签不匹配 - PhpWord 错误

php - 拉拉维尔 5.1 : how can i get nested relation from model?

php - 印度卢比符号未在 Windows 上显示 (7,8) 即使在 Linux 上也显示

php - 多行插入插入 2 行额外的 0