我尝试使用“->find(X)”或“->where”从表中获取行,但返回错误。我想我错过了一些东西,但我不知道是什么。
<?php
class SnippetsController extends BaseController {
public $restful = true;
public function index($id)
{
$snippet = SnippetsController::where('id', '=', 11)->get();
我尝试使用 find 但注意到有帮助。
$snippet = SnippetsController::find(11);
有“->get”和没有“->get”。但注意到作品。我在表本身中有“11”id,并且该错误似乎与它无关。
也许我需要将类(class)扩展到 Eloquent?如果是这样,我如何将 BaseController 保持在其之上?
谢谢!
错误:
BadMethodCallException Method [find] does not exist.
最佳答案
你一定有一个名为 Snippet 的模型,对吧?这就是你如何使用它:
$snippet = Snippet::find(11);
您的 SnippetsController
未绑定(bind)到数据库 (Eloquent ORM),因此您必须创建(如果还没有)模型:
class Snippet extends Eloquent {
}
关于Laravel 4 - 方法 [where] 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22619772/