【问题标题】:Pagination links is not show when using paginate in laravel在 laravel 中使用分页时不显示分页链接
【发布时间】:2022-01-18 09:41:54
【问题描述】:

所以我在这里遇到了一些问题,我的输出数据上没有显示链接,我尝试过这样的查询:

$getData = Inventory::select('id_inventory', 'inventory_code', 'inventory_id_location', 'inventory_id_category', 'date_of_buy', 'price_of_item', 'condition_of_item', 'description', 'created_by', 'edited_by')
                ->selectRaw('group_concat(inventory_id_category) as inventory_id_categories')
                ->selectRaw('group_concat(id_inventory) as id_inventories')
                ->with(['categories' => function ($query) {
                    $query->select('id_category', 'category_code', 'category_name');
                }])
                ->with(['locations' => function ($query) {
                    $query->select('id_location', 'location_name');
                }])
                ->with(['delivery_inventories' => function ($query) {
                    $query->select('id_delivery', 'delivery_id_inventory', 'delivery_id_location', 'delivery_date', 'deliver_by', 'description')
                    ->with(['location_deliveries' => function ($query) {
                        $query->select('id_location', 'location_name');
                    }]);
                }])
                ->whereHas('categories', function ($query) use ($search) {
                    $query->orWhere('category_code', 'like', "%{$search}%")
                        ->orWhere('category_name', 'like', "%{$search}%");
                })
                ->whereHas('locations', function ($query) use ($search) {
                    $query->orWhere('location_name', 'like', "%{$search}%");
                })
                ->whereHas('delivery_inventories', function ($query) use ($search) {
                    $query->orWhere('delivery_date', 'like', "%{$search}%")
                        ->orWhere('deliver_by', 'like', "%{$search}%")
                        ->orWhere('description', 'like', "%{$search}%");
                })
                ->where('inventory_code', 'like', "%{$search}%")
                ->orWhere('price_of_item', 'like', "%{$search}%")
                ->orWhere('condition_of_item', 'like', "%{$search}%")
                ->orWhere('description', 'like', "%{$search}%")
                ->groupBy('inventory_code')
                ->orderBy('inventory_code')
                ->paginate(10);

        return response()->json([
            'get_data' => $getData
        ], 200);

但在我的控制台上,结果如下:

我想问任何错误或未完成的查询,所以我的链接不会显示在我的控制台上?有什么建议吗?谢谢。

我之前的项目(但我不能在我当前的项目中使用它):

【问题讨论】:

  • next_page_urllast_page_url 看起来像是指向我的分页链接。我错过了什么吗?
  • 分页所需的任何信息都在此 JSON 中 - 根据该信息构建您的分页。 JSON中不会有“Prev”、“Next”、1,2,3...链接
  • @apokryfos,我已经更新了我的问题,希望我的问题有更清晰的解释
  • @brombeer,在我以前的项目中没有先生,我可以使用链接,但现在我不能使用它
  • 看起来links 是在 Laravel 8.0.3 中添加的,所以这个项目可能更旧?

标签: laravel pagination


【解决方案1】:

您是否更新了 AppServiceProvider? 如果不去 app/providers/AppServiceProvider.php 并在其中添加分页器。

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Paginator::useBootstrap();
    }
}

【讨论】:

  • 感谢先生的建议,但我应该像您自己一样更新AppServiceProvider 吗?因为在以前的项目中我没有对该文件进行更改
  • 这个变化发生在 laravel 8 中。在 appserviceprovider 中添加分页器并测试它。如果不工作,你可以删除它
  • 我已经尝试过了,但是出现了一些错误,先生,我的错误是这样的Call to undefined method Illuminate\Pagination\Paginator::useBootstrap()我该怎么办?
  • 使用 Illuminate\Pagination\Paginator;你也加了这行吧?
  • 好吧,我已经解决了我的问题,问题是我必须将我的 laravel 项目更新到 laravel 8 但我当前的项目版本使用的是 laravel 7,谢谢大家
猜你喜欢
  • 2013-04-07
  • 1970-01-01
  • 1970-01-01
  • 2020-05-27
  • 2012-07-30
  • 2017-12-23
  • 2021-12-08
  • 2014-02-26
  • 1970-01-01
相关资源
最近更新 更多