生产服务器上的composer软件包出现问题-Laravel项目

时间:2018-10-31 19:29:47

标签: php laravel composer-php

当特征方法调用时,我的问题是BadMethodCallException。 该软件包是Laravel的kalnoy / nestedset。在我的本地服务器上,所有工作都完美无缺,但是随后我在生产服务器上创建了我的应用程序,总是遇到以下异常: 方法Illuminate \ Database \ Query \ Builder :: descendants不存在。

我尝试不做的事情: 1.作曲家 2.作曲家转储自动加载 3.几次删除和部署项目 4.作曲家需要kalnoy / nestedset 5.大量的谷歌搜索。 有什么想法吗?有谁遇到过这样的问题并感到高兴吗?

我的模型:

namespace App;

use Illuminate\Database\Eloquent\Model,
    Kalnoy\Nestedset\NodeTrait;

class Category extends Model
{
    use NodeTrait;

    protected $table = 'categories';

    public function getOnMainItems($limit = 6)
    {
        return Category::where('main', 1)->limit($limit)->get();
    }
}

计算“不存在”的内容:

namespace App\Services;

use App\Category;
use Kalnoy\Nestedset\Collection;

class CategoryService
{

    /**
     * @param string $slug
     * @return array $categories
     */
    public function getCatalogCategoriesForFilter(string $slug = '')
    {
        $categories = [];
        if ($slug !== '') {
            $currentCategory = Category::where([['category_slug', $slug], ['active', 1]])->limit(1)->get();
            $categoriesByParent = Category::defaultOrder()->descendantsOf($currentCategory[0]->id);
            foreach ($categoriesByParent as $category) {
                $categories[] = $category->id;
            }
        }
        return $categories;
    }
}

我的composer.json文件

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": "^7.1.3",
    "darryldecode/cart": "~4.0",
    "doctrine/dbal": "^2.8",
    "fideloper/proxy": "^4.0",
    "kalnoy/nestedset": "^4.3",
    "laravel/framework": "5.6.*",
    "laravel/tinker": "^1.0",
    "predis/predis": "^1.1"
},
"require-dev": {
    "filp/whoops": "^2.0",
    "fzaninotto/faker": "^1.4",
    "mockery/mockery": "^1.0",
    "nunomaduro/collision": "^2.0",
    "phpunit/phpunit": "^7.0"
},
"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/"
    }
},
"extra": {
    "laravel": {
        "dont-discover": [
        ]
    }
},
"scripts": {
    "post-root-package-install": [
        "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "@php artisan key:generate"
    ],
    "post-autoload-dump": [
        "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
        "@php artisan package:discover"
    ]
},
"config": {
    "preferred-install": "dist",
    "sort-packages": true,
    "optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true

}

谢谢大家。

更新: 错误消息:

(1/1) BadMethodCallException
Method Illuminate\Database\Query\Builder::descendants does not exist.

in Builder.php line 2816
at Builder->__call('descendants', array(2))
in Builder.php line 1286
at Builder->__call('descendants', array(2))
in CategoryService.php line 38
at CategoryService->getCatalogCategories('postelnoe-bele')
in GoodsController.php line 41

1 个答案:

答案 0 :(得分:0)

感谢所有帮助我的人。 我很喜欢这个。

问题出在

componentDidMount () {
     const script = document.createElement("script");

     script.src = "https://platform.twitter.com/widgets.js";
     script.async = true;

     document.body.appendChild(script);
}

Category :: where('active',1)返回queryBuilder对象,该对象没有后代方法,适用于Category(模型对象)。

正确的方法是

Category::where('active', 1)->descendants($categoryId);

我很尴尬,因为在我的本地服务器上无法正常工作。如果有人可以解释这件事,我将不胜感激。