Laravel调用未定义的方法。方法存在

问题描述 投票:0回答:2

我有以下错误:

Symfony \ Component \ Debug \ Exception \ FatalThrowableError

调用未定义方法App \ Shop :: getItems()

Shop.php

public function getItems()
{


    foreach ($this->items as $item) {

        //$coverUrl = "https://SomeCoverUrl";
        $productId = $item['id'];

        $coverUrl = Product::find($productId)->images()->where('type', 'like', '%cover%')->get()->first();


        if (empty($coverUrl)) {
            $coverUrl = "https://via.placeholder.com/300C/O%20https://placeholder.com/";
        } else {
            $coverUrl = $coverUrl->img_url;
        }

        $item['cover'] = $coverUrl;

        $platformName = Product::find($productId)->platform()->get()->first()->platform;

        $item['platform'] = $platformName;

        $item['region'] = Product::find($productId)->regions()->get()->first()->region;

        //Pricecalculation

        $priceArr = [];
        $countPrice = 0;
        foreach (Currency::all() as $currency) {

            //Symbol
            $priceArr[$countPrice][0] = number_format($item->price_100 * 1.49 * $currency->exchange_rate, 2);
            //value
            $priceArr[$countPrice][1] =  $currency->symbol;
            $countPrice++;
        }

        $item['price'] = $priceArr;
    }

    return $this->items;
}

ProductController.php

public function searchBar($search)
{

    $search = str_replace('-', ' ', $search);
    $product = Product::where('title', 'like', '%' . $search . '%')->paginate(10);

    $shop = new Shop($product);

    return $shop->getItems();
}

昨天功能正常工作。

现在Shop Object的所有功能不起作用。

已经在命令行上运行以下命令:

composer dump-autoload

php artisan明确编译

php artisan cache:clear

任何解决方案?

laravel methods undefined call
2个回答
0
投票

将此行放在namespace下方的控制器顶部(如果有代码的话)


0
投票

检查dd是否在此返回->

© www.soinside.com 2019 - 2024. All rights reserved.