【问题标题】:Laravel 4.2 First Model Connecting to EloquentLaravel 4.2 第一个连接 Eloquent 的模型
【发布时间】:2014-10-03 09:51:17
【问题描述】:

所以这是我第一次使用 Laravel v4.2

很混乱,因为 error.log 信息太少了。

我想创建一个名为 Author 的新模型

这是我的 routes.php

Route::get('authors', 'AuthorsController@IndexAction');

这是我的 AuthorsControllers.php

<?php

class AuthorsController extends BaseController {

    public $restful = true;
    public $layout = 'layouts.default';

    public function indexAction(){
        return  View::make('authors.index')
            ->with('title', 'Authors and Books')
            ->with('authors', Author::all())
            ;
    }

    public function getView($id){
        return View::make('authors.view')
            ->with('title', 'Author View Page')
            ->with('author', Author::find($id))
            ;
    }
}

这是我的Author.php

<?php
class Authors extends Eloquent {
}

我收到了这个错误日志

[20

14-10-03 01:37:43] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'Author' not found' in C:\xampp\htdocs\laravel-master\app\controllers\AuthorsController.php:11
Stack trace:

#0 [internal function]: Illuminate\Exception\Handler->handleShutdown()

#1 {main} [] []

我想知道问题出在哪里?因为我已经关注了所有这个链接页面 http://laravel.com/docs/4.2/quick#creating-a-view

请记住,我使用 Authors 创建了控制器,使用 Author 创建了模型。

【问题讨论】:

  • 仅供参考,数据库已经创建。我有 4 条记录

标签: php debugging laravel laravel-4 routes


【解决方案1】:

你需要改变

class Authors extends Eloquent {

class Author extends Eloquent {

可能在进行更改后也需要运行composer dump-autoload(我不记得了)

【讨论】:

  • 您在应用程序的根目录中运行它。但首先对文件进行更改,看看它是否有效 - 更改后您可能不需要运行 composer。
  • 那么作曲家转储自动加载有什么用?
  • composer dump-autoload -o,用于生成类加载器,如果你添加新类,它不会被包含在你的类加载器中,除非你使用该dump-autoload更新它。
  • @RaffyCortez 很好的答案,所以回答我对 Laravel 的问题stackoverflow.com/questions/27244277/…
猜你喜欢
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 2019-10-04
  • 2015-05-23
  • 2017-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多