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?
Any chance you have a foreach above it where you reassign $prod?
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
@davy_yg I asked a question. I didn't suggest to do a foreach. Can you show the full file contents?
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>
Bingo. Here you overwrite $prod
@foreach($chunk as $prod)
//fix
@foreach($chunk as $product)
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 ?
@davy_yg yeah those are two different things
@davy_yg consider using proper names
For example
$products = Product::paginate(12);
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.