pentium's avatar

Pagination links() method doesn't exist

i have seen so many related topics to this problem but i could not find the solution. i am using pagination with eloquent but on my view i can not have access to the method links()

 public function myadd( Request $request ){

      $ads = ads::where("userId",Auth::user()->id)->paginate(3); 
     return view('clients.myadd')->with("ads",$ads);
 }

this is my view :

 @foreach($ads as $ads)

          <div class="m-0">
                <button  class="btn myadd-btn btn-primary btn-sm" type="button"  >View</button> 
                <button  class="btn myadd-btn btn-primary btn-sm" type="button"  >Update</button> 
                <button  class="btn myadd-btn btn-primary btn-sm" type="button"  >Sold Out</button> 
                <button  class="btn myadd-btn btn-primary btn-sm" type="button"  >Delete</button> 
            </div>

          <div class="container myaddContainer">
            <div class="row">
              <div class="col-md-2 col-lg-2 p-0" >
               <img src="publication/{{$ads->pict1}}" width="100px"; height="109px;">
              </div>
              <div class="col-md-10 col-lg-10 m-0 p-0" >
                <div class="row m-0 p-0">
                 <h5>{{$ads->title}} 
                  (@if($ads->isUsed==0)
                  {{"New"}}
                  @else
                  {{"Used"}}
                  @endif)
                </h5> 
                </div>
                <div class="row m-0 p-0" >
                  <span>{{$ads->cityName}} </span> &nbsp;&nbsp;||&nbsp;&nbsp;<span> {{$ads->subCategoryName}}</span>
                  
                </div>
                <div class="row m-0 p-0" >
                  <span class="price" >{{$ads->price}} TK</span> <span class="time">{{$ads->created_at->diffForHumans()}}</span>
                  
                </div>
                
              </div>
              
            </div>
            
          </div> 
          @endforeach
          {{ $ads->links() }}

the error i am getting:

Call to undefined method App\ads::links() (View: D:\xamp\htdocs\bigdeals.com\resources\views\clients\myadd.blade.php)
0 likes
5 replies
lightyagami's avatar
Level 1

write your loop of this way

@foreach($ads as $ad)
@endforeach

also, in your code you have a $ads->links(); outside of the loop. show us the output of $ads

with: {{ dd($ads) }}

jlrdw's avatar

as $ad not $ads as $ads

1 like
jlrdw's avatar

Give @lightyagami best answer, he got it first, I was typing same time, but stepped away, thanks

Please or to participate in this conversation.