Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未定义的雄辩方法find($id)/all()_Php_Laravel_Eloquent - Fatal编程技术网

Php 未定义的雄辩方法find($id)/all()

Php 未定义的雄辩方法find($id)/all(),php,laravel,eloquent,Php,Laravel,Eloquent,我试着用Laravel和雄辩的语言创建简单的模型。 下面是我的代码示例: composer.json "laravel/framework": "4.1.*" routes.php Route::controller('items', 'ItemsController'); Route::get('item/{item}', array('as'=>'item', 'uses'=> 'ItemsController@getView')); php artisan路由: | | G

我试着用Laravel和雄辩的语言创建简单的模型。 下面是我的代码示例:

composer.json

"laravel/framework": "4.1.*"
routes.php

Route::controller('items', 'ItemsController');
Route::get('item/{item}', array('as'=>'item', 'uses'=> 'ItemsController@getView'));
php artisan路由:

| | GET item/{item}    | item | ItemsController@getView    |    |    |
| | GET items          |      | ItemsController@getIndex   |    |    |
controllers/ItemsController.php

<?php

class ItemsController extends BaseController {
    public function getIndex()
    {
        $items = Item::all();
        return View::make('items.index')
            ->with('title', 'Index show')
            ->with('items', $items);
    }

    public function getView($id)
    {
        return View::make('items.view')
            ->with('title', 'View show')
            ->with('items', Item::find($id));
    }

}
当我尝试获取mydomain/item/2时 拉雷维尔说:

Call to undefined method Item::find()
并获取mydomain/items/

Call to undefined method Item::all()

我错过了什么?

当我“动态”更改模型和表名时,以及当我执行大量的迁移回滚时,这种情况有时会发生在我身上。尝试重命名您的模型名,它在大多数情况下适用于我

你确定你用的是雄辩的课堂吗?我不知道Laravel的情况,但是Eloquent类应该有find()和all()方法,除非定义必须编写这些方法。Laravel是否需要
使用名称空间\雄辩的
句子?您是否做了
作曲家转储自动加载
?@Jorge Laravel自己做的哇,这解决了我的问题,谢谢!那看起来像个虫子,或者可能是“缓存”?你搞定了!杰出的
Call to undefined method Item::find()
Call to undefined method Item::all()