尝试分页时调用未定义的方法 Illuminate\Database\Eloquent\Builder::links() 错误

Call to undefined method Illuminate\Database\Eloquent\Builder::links() error when attempting to paginate

我正在尝试创建一个简单的过滤系统,其中包含搜索框、服务、类别以及对 laravel 控制器中的项目进行排序的方法。但是,当我尝试过滤任何内容时,我收到错误链接(),即使我认为我已经正确分页。这是我的函数:

public function Search(Request $request){

        $search_service=$request->service;
        $search_order=$request->order;
        $search_category=$request->category;
        $search_text=$request->searchModel;


        $items=Item::where(function($query)use($search_text){
                    $query->where('model_name','like',"%{$search_text}%")
                          ->orWhere('description','like',"%{$search_text}%")                            
                          ->orWhere('model_tags','like',"%{$search_text}%");});

        if ($search_service){
            $items->where('service','=',$search_service);
        }

        if($search_category){
            $items->where('category','=',$search_category);
        }

        if($search_order){
            if($search_order =="description" or $search_order=="model_name" or $search_order=="version" or $search_order=="created_at"){
                        $items->orderBy($search_order);
                    }
                    else if($search_order=="versionDesc"){
                        $items->orderBy('version','desc');
        
                    }
                    else if($search_order=="createDesc"){
                        $items->orderBy('created_at','desc');
                    }
                
        }
            $items->paginate(5)->withQueryString();

        return view('admin.item.search',compact('items'));
    }

任何人都可以就这个问题给我一些建议吗?谢谢!

编辑:

这是我的搜索页面:

@extends('admin.admin_master')
@section('admin')

{{-- Not placed in app.css as it affects the scroll bar --}}
<style>
.formForService {
  text-align: center;
}

.searchForm{
  margin: 0 auto; 
  width:250px;
}

#show_image_popup{
  width: 1200px;
  height: 700px;
  border: 1px solid #333;
  box-sizing: border-box;
  padding: 5px;
  text-align: center;
  overflow-y:scroll;
  position: fixed;
  
  top: 55%;
  left: 55%;
  transform: translate(-50%, -50%);
  background: #e5e5e5;
/*    */
  display: none;
}
#show_image_popup img{
  max-width: 90%;
  height: auto;
}

.clickModel{
display: block;
margin-left: auto;
margin-right: auto;
width:1100px;
height:670px;
}
</style>
<div class="content-wrapper">
  <div class="container-full">
    <!-- Content Header (Page header) -->

    

    <!-- Main content -->
    <section class="content">
      <div class="row">
          
      

        <div class="col-12">

         <div class="box">
            <div class="box-header with-border">
              <h3 class="box-title">All Models</h3>
              <a href='{{ route('add.models') }}' class="btn btn-rounded btn-success mb-5"style="float:right">Add model</a>
            </div>
            <!-- /.box-header -->
            
              <div class="table-responsive">
                <table class="table table-bordered table-striped">
                  
                  <thead>
                      <tr></tr>
                          <th width="5%">No.</th>
                          <th>Name</th>
                          <th width="10%">Image</th> 
                          <th>Description</th>
                          <th>Version</th>
                          <th>Created at</th>
                          <th width="8%">Modify</th>
                          
                      </tr>
                  </thead>
                  <tbody>

                    
                    
                    @if($items)
                    @foreach($items as $key=>$item)
                      <tr>
                        <th scope="row">{{ $items->firstItem()+$loop->index}}</th>
                        <td>{{ $item->model_name }}</td>
                          <td><model-viewer class="small-image" src="{{ asset($item->model_image) }}"alt=""auto-rotate="" camera-controls="" background-color="#455A64"></model-viewer></td>
                          <td>{{ $item->description }}</td>
                          <td>{{ $item->version }}</td>
                          <td>
                            @if($item->created_at == NULL)
                            <span class="text-danger"> No Date Set </span>
                            @else
                            {{ Carbon\Carbon::parse($item->created_at)->diffForHumans() }} {{-- Carbon needed for query builder --}}
                            @endif
                        </td> 
                        <td>
                          <a href="{{ url('model/download/'.$item->id) }}"class="btn btn-app btn-success"><i class="fa fa-save"></i>Download</a>
                          <a href="{{ url('model/view/'.$item->model_name) }}"class="btn btn-app btn-primary"><i class="fa fa-inbox"></i>View</a>
                          <a href="{{ url('model/edit/'.$item->id) }}"class="btn btn-app btn-info" ><i class="fa fa-edit"></i>Edit</a>
                          
                      </td>
                  
                          
                      </tr>
                      @endforeach
                      @else
                  <td>No records found</td>
                  @endif
                  </tbody>
                  

                  
                  
                  
                </table>
                {{ $items->links() }}
                  
                  
                </div>
        
          </div>
          <!-- /.box -->

          
          <!-- /.box -->          
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  
  </div>
</div>
</div>
<div id="show_image_popup">
  <div class="close-btn-area">
    <button type="button" style="float:right" class="btn btn-circle btn-danger btn-lg mb-5" id="close-btn">X</button>
  </div>
  <div id="image-show-area">
      <model-viewer class="clickModel"  id="large-image" alt=""auto-rotate="" camera-controls="" background-color="#455A64"></model-viewer>
  </div>
</div>





@endsection

您需要赋值:

$items = $items->paginate(5)->withQueryString();

如果你不这样做,你的分页器实例就会丢失,你最终会在视图中看到一个没有链接方法的构建器