【发布时间】:2015-12-05 13:46:37
【问题描述】:
找不到我的班级“文章”的控制器。
我需要从文章表中获取所有条目。
我可以使用 DB:: 外观来提取数据库中的内容,但是当我尝试使用 Article::all() 时,我得到:
Class 'App\Http\Controllers\Article' not found
in ArticleController.php line 15
at Application->Laravel\Lumen\{closure}()
第 15 行如下所示:
$article = Article::all();
这是我迄今为止尝试过的,但没有成功:
将 .env.example 更新为 .env 并设置我的数据库凭据。
在 bootstrap/app.php 中我已取消注释
Dotenv::load(__DIR__.'/../');在 bootstrap/app.php 中我已取消注释
$app->withFacades(); $app->withEloquent();我尝试在routes.php中使用控制器的完整路由:
$app->get('article', 'App\Http\Controllers\ArticleController@index');
我的模型目录位于 app->Models 下,里面有我的 Article.php 模型:
<?php
# app/Models/Article.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $table = 'articles';
protected $fillable = ['title', 'content'];
}
我的控制器是 ArticleController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ArticleController extends Controller{
public function index(){
$article = Article::all();
return response()->json($article);
}
}
还有我的 routes.php
<?php
$app->get('article', 'ArticleController@index');
非常感谢您对此错误的任何帮助。不幸的是,我花了 2 天的大部分时间在这上面。
谢谢。
【问题讨论】: