Laravel 5.6应用程序中不存在方法链接?

时间:2018-11-03 12:32:46

标签: php laravel search pagination algolia

使用laravel 5.6并在我的管理员中,我有两个表,例如vehicle和uploads。与这两个表的关系是, 车辆型号,

public function uploads()
    {
        return $this->hasMany(Upload::class);
    }

和上传模型,

 public function vehicle()
    {
        return $this->belongsTo(Vehicle::class);
    }

我的VehicleController中具有以下索引功能,

 $vehicles = Vehicle::with('uploads')
            ->orderBy('adtype','DESC')

            ->latest('updated_at')
            ->paginate(5);

            return view('vehicles.index')->withVehicles($vehicles);

索引刀片文件是

<form method="GET" action="{{ url('search') }}">
      {{csrf_field()}}
            <div class="row">
                <div class="col-md-6">
                    <input type="text" name="search" class="form-control" placeholder="Search">
                </div>
                <div class="col-md-6">
                    <button class="btn btn-info">Search</button>
                </div>
            </div>
        </form>

        <br> 

@forelse( $vehicles as $vehicule )


                    @if( $vehicule->uploads->count() > 0 )
                        <a href="{{ route('vehicles.show', $vehicule->id) }}">
                            @php
                                $upload = $vehicule->uploads->sortByDesc('id')->first();
                            @endphp

                            <div style="border-style: solid; background-color: {{ $vehicule->adtype === 1 ? '#FFEFD5' : '#FFFFFF' }} ">
                            <img src="/images/{{ $upload->resized_name }}" height="150" width="250"></a>


                        {{ Carbon\Carbon::parse($vehicule->created_at)->diffForHumans()}} 
                            {{$vehicule->provincename}}
                          {{$vehicule->milage}}

                          </div>
<br>
                           <hr>

                    @endif

            @empty
                <td>No Advertisment to display.</td>
            @endforelse

</div>

</div>
</div>
{{ $vehicles->links() }}
</div>
@endsection

我的分页工作正常,但是在我的索引文件中,我使用了algolia搜索输入。当我使用关键字并单击“搜索”按钮时,发生以下错误,

(2/2) ErrorException

Method links does not exist. (View: C:\Users\banda\Desktop\ddddd\resources\views\vehicles\index.blade.php)

当我在视图文件中删除{{$ vehicles-> links()}}时,它正在工作。 如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您可以尝试

{{ $vehicles->render() }}

代替-> links()吗?

------编辑

您可以尝试像这样传递数据以查看吗?

 $vehicles = Vehicle::with('uploads')
        ->orderBy('adtype','DESC')
        ->latest('updated_at')
        ->paginate(5);

        return view('vehicles.index')->with(['vehicles' => $vehicles]);

然后检查?