方法链接不存在 - Laravel 5.5

Method links do not exist - Laravel 5.5

我收到以下错误:

Method links do not exist

我也试过渲染函数,它给了我同样的结果。

这是我的代码:

public function welcome() {
    $products = DB::table('products')->paginate(12);
    return view('welcome', compact('products', $products));
}

当我调用 {{ $products->links() }} 时,它显示错误,但如果我删除 {{ $products->links() }},我可以看到结果。

这是我的观点:

    @foreach($products as $product)
    <div class="col-sm-6 col-md-4 col-lg-3">
        <!-- Product item -->
        <div class="product-item hover-img">
            <a href="product_detail.html" class="product-img">
                <img src="images/default.png" alt="image">
            </a>
            <div class="product-caption">
                <h4 class="product-name"><a href="#">{!! $product->name !!}</a></h4>
                <div class="product-price-group">
                    <span class="product-price">{!! $product->price !!} KM</span>
                </div>
            </div>
            <div class="absolute-caption">
                <form action="{!! route('store') !!}" method="POST">
                    {!! csrf_field() !!}
                    <input type="hidden" name="id" value="{{ $product->id }}">
                    <input type="hidden" name="name" value="{{ $product->name }}">
                    <input type="hidden" name="price" value="{{ $product->price }}">
                    <input type="submit" class="btn btn-success btn-lg" value="Dodaj u korpu">
                </form>
            </div>
        </div>
    </div>
    @endforeach

   {{ $products->links() }}

您应该使用 Eloquent 而不是查询生成器。

使用:

$products = \App\Product::paginate(12);

而不是

$products = DB::table('products')->paginate(12);

使其发挥作用。

(当然你需要先创建Product模型扩展Eloquent模型)