BadMethodCallException方法orderBy不存在

时间:2015-12-16 17:47:59

标签: php database orm

模型

<?php

class CommentComentario extends Illuminate\Database\Eloquent\Model {

    protected $table = 'comment_comentario';

    public function comercio() {
        return $this->belongsTo('CommentComercio', 'comercio_id', 'id');
    }
}

请求

$comercios = CommentComercio::all()->orderBy('created_at');
  

错误产生于 illuminate \ support \ Traits \ Macroable.php第81行

安装作曲家

{
    "require": {
        "slim/slim": "2.*",
        "slim/extras": "*",
        "illuminate/console": "*",
        "illuminate/database": "*",
        "illuminate/events": "*",
        "illuminate/filesystem": "*",
        "facebook/php-sdk-v4": "*",
        "monolog/monolog": "1.*",
        "twig/twig": "*",
        "phpmailer/phpmailer": "~5.2"
    },
    "autoload": {
        "classmap": [ "models" ]
    }
}

1 个答案:

答案 0 :(得分:3)

更改此行:

$comercios = CommentComercio::all()->orderBy('created_at');

对此:

$comercios = CommentComercio::orderBy('created_at')->get();

这将得到所有&#34;您的商品仍然存在,但已将订单应用于该商品。