davy_yg's avatar
Level 27

Call to undefined method App\Product::links()

BadMethodCallException Call to undefined method App\Product::links() (View: E:\xampp75\htdocs\axe-backend-mg\resources\views\store\catalog.blade.php)

catalog.blade.php

	@if($prod != null)
        	{{ $prod->links('layout.page') }}
    @endif

StoreController.php

	public function men()
	{
    		$totalcarts = CartRepo::getTotalCart();
    		$prod = Product::paginate(12);

    		return view('store.catalog', compact('prod', 'totalcarts'));
	}

ref: https://stackoverflow.com/questions/67657704/call-to-undefined-method-app-models-adslinks

Any clue why the error exists?

0 likes
9 replies
Sinnbeck's avatar

Any chance you have a foreach above it where you reassign $prod?

davy_yg's avatar
Level 27

Call to a member function links() on bool (View: E:\xampp75\htdocs\axe-backend-mg\resources\views\store\catalog.blade.php)

catalog.blade.php

		@if($prod != null)
				@foreach($prod as $p)
				
          		{{ $p->links('layout.page') }}
        	
        	@endforeach	
    		@endif
Sinnbeck's avatar

@davy_yg I asked a question. I didn't suggest to do a foreach. Can you show the full file contents?

davy_yg's avatar
Level 27

catalog.blade.php

   <div class="col-md-9">

		<div class="row">
		@foreach($prod->chunk(1) as $chunk)

		<div class="col-md-4">

			@foreach($chunk as $prod)

				<a href="{{ url('prod_detail') }}"><img class="img-fluid" src="{{ url(Storage::url($prod->prod_main_img)) }}"></a><br><br>
				<span class="price">Rp. 325.000</span><span class="prod"><img src="{{ url('store/images/catalog/cart_icon.png') }}" width="35"><a href="{{ route('prod_detail', $prod->id) }}">DETAILS</a></span>
				<br><br>
				<span class="prod-ctitle">{{ $prod->prod_name_en }}</span><span class="orange-star">@if(auth()->user())<a href="{{ url('wishlist/add/'.auth()->user()->id.'/'.$prod->id) }}"><img style="float: right; margin-top: -15px;" src="{{ url('store/images/catalog/wishlist.jpg') }}"></a>@else<a href="{{ url('login') }}"><img style="float: right; margin-top: -15px;" src="{{ url('store/images/catalog/wishlist.jpg') }}"></a>@endif</span><br><br><br><br>

			@endforeach

		</div>
				
		@endforeach	
		</div>
	
	</div>

	</div>

		<span class="float-right">
			@if($prod != null)
				
          		{{ $p->links('layout.page') }}
        	
    		@endif
        </span><br><br><br><br>
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Bingo. Here you overwrite $prod

@foreach($chunk as $prod)
//fix
@foreach($chunk as $product)
davy_yg's avatar
Level 27

Wow, do I write it twice?

	@foreach($prod->chunk(1) as $chunk)

		<div class="col-md-4">

			@foreach($chunk as $product)

after the $chunk it should be different from the origin $prod ?

Sinnbeck's avatar

@davy_yg consider using proper names

For example

$products = Product::paginate(12); 
davy_yg's avatar
Level 27

I must have replace my previous $list with $prod which makes it identical to the $prod after the $chunk.

Please or to participate in this conversation.