0
votes

I have the following error :

Symfony\Component\Debug\Exception\FatalThrowableError

Call to undefined method 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();
}

Yesterday the function works fine.

Now all functions of Shop Object do not work.

Already run following commands on commandline :

composer dump-autoload

php artisan clear-compiled

php artisan cache:clear

Any solution ?

EDIT :

Shop.php

public function something()
{
    return 1;
}

ProductController.php

    $shop = new Shop();
    $shop->something();

Returns the same error "Call to undefined method"

3
i am sure you didn't forget to write use App\Shop in controllerMeera Tank
I didn't forget to write use App\Shop; in controllerMaaax i
I'm doubtful about your $shop var whether it instantiated rightlySumit Wadhwa

3 Answers

0
votes

Check what dd returns in this ->

 $shop = new Shop($product);

Edit : Ok ,maybe namespace has a problem try :

use App\Shop as MyShop;

Then

$shop=new MyShop($product);
0
votes

I don't know what the problem is with my Class Shop. Now I created a new class 'Shopitem', paste same code & now it works.

0
votes

You shouldn't pass your product variable to the defined class. If you want to pass $product value to a method in shop class use it like this:

$shop = new Shop();
$shop->getDetails();