【发布时间】:2016-06-16 15:46:09
【问题描述】:
我想在 laravel 5.2 应用程序中创建一个下拉列表。我想在我的视图页面中加载类别项目。但是当我加载页面时它显示以下错误。
routes.php 第 47 行中的 FatalErrorException:找不到类“类别”
如果有人知道问题出在哪里,请帮我完成它。
这是我的类别模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model{
protected $table="categories";
protected $fillable = ['name'];
}
路线如下:
<?php
Route::get('/', function () {
$categories=Category::all();
return view('index')->with ('categories',$categories);
});
如果需要,这里是查看页面:
<html>
<head>
<title>Cascading Dropwon</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
<h3>Categories and Subcategories Ajax</h3>
<div class="col-lg-4">
{!! Form::open(array('url' => '','files'=>true)) !!}
{!! Form::token(); !!}
<div class="form-group">
<label for="">Categories</label>
<select class="form-control input-sm" name="">
@foreach($categories as $category){
<option value="{{$category->id}}">{{$category->name}}</option>
}
@endforeach
</select>
</div>
<div class="form-group">
<label for="">Sub Categories</label>
<select class="form-control input-sm" name="">
<option value=""></option>
</select>
</div>
{!!Form::close()!!}
</div>
</div>
</body>
</html>
【问题讨论】:
-
你试过
composer dump-autoload吗?
标签: php laravel laravel-routing laravel-5.2