在页面中显示两次拉维尔分页链接

我在我的一个项目中实现了一个拉拉维尔分页,其中分页像一个魅力一样工作。


我要求在表的顶部和表的底部显示分页链接。喜欢这个


{!! $entries->render() !!}

<table class="table table-responsive" id="entries-table">

    <thead>

        <tr>

                <th>ID</th>

                <th>Advisor name</th>

        </tr>

    </thead>

    <tbody>

    @forelse($entries as $entries)

        <tr>

            <td> {{ $entries->id }} </td>

            <td> {{ $entries->name }} </td>

        </tr>

    @empty

    <tr>

        <td>

            <p>No record found.</p>

        </td>

    </tr>

    @endforelse

    </tbody>

</table>

{!! $entries->render() !!}

当我尝试在表格底部或同一页面的任何地方再使用一次时,它会给我带来以下错误。{!! $entries->render() !!}


错误异常 (E_ERROR) 调用未定义的方法 应用程序\模型\条目::render()


这是我的控制器代码


public function index(Request $request)

    {            

        $entries = Entries::orderBy('id', 'DESC')->paginate(15);


        return view('entries.index')

            ->with('entries', $entries);

    }

在这里,我正在使用控制器转储变体,这就是我得到的。$entriesdd($entries)


LengthAwarePaginator {#425 ▼

  #total: 215

  #lastPage: 15

  #items: Collection {#436 ▼

    #items: array:15 [▼

      0 => entries {#437 ▶}

      1 => entries {#438 ▶}

      2 => entries {#439 ▶}

      3 => entries {#440 ▶}

      4 => entries {#441 ▶}

      5 => entries {#442 ▶}

      6 => entries {#443 ▶}

      7 => entries {#444 ▶}

      8 => entries {#445 ▶}

      9 => entries {#446 ▶}

      10 => entries {#447 ▶}

      11 => entries {#448 ▶}

      12 => entries {#449 ▶}

      13 => entries {#450 ▶}

      14 => entries {#451 ▶}

    ]

  }

  #perPage: 15

  #currentPage: 1

  #path: "https://samplesite.com/entries/11"

  #query: []

  #fragment: null

  #pageName: "page"

  +onEachSide: 3

  #options: array:2 [▼

    "path" => "https://samplesite.com/entries/11"

    "pageName" => "page"

  ]

}

查看此视频,我与您分享以获得更好的想法


慕容森
浏览 117回答 4
4回答

撒科打诨

您不应该在前言上的变量中给出相同的名称,这可能会导致.errors之间的冲突,这可能是因为变量的abigu来自雄辩的结果或循环中的结果。尝试像这样重构你的代码@forelse($entries as $entrie)&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; <td> {{ $entrie->id }} </td>&nbsp; &nbsp; &nbsp; &nbsp; <td> {{ $entrie->name }} </td>&nbsp; &nbsp; </tr>@empty<tr>&nbsp; &nbsp; <td>&nbsp; &nbsp; &nbsp; &nbsp; <p>No record found.</p>&nbsp; &nbsp; </td></tr>@endforelse

沧海一幻觉

您正在用 中的集合项覆盖集合。$entries@forelse@forelse($entries as $entries)&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; <td> {{ $entries->id }} </td>&nbsp; &nbsp; &nbsp; &nbsp; <td> {{ $entries->name }} </td>&nbsp; &nbsp; </tr>@empty更改为 :$entries$entry@forelse($entries as $entry)&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; <td> {{ $entry->id }} </td>&nbsp; &nbsp; &nbsp; &nbsp; <td> {{ $entry->name }} </td>&nbsp; &nbsp; </tr>@empty

潇潇雨雨

确保在边栏选项卡中返回确切的集合。$users= User::paginate(15);return view('entries', compact('users'));并且您已经可以在刀片中使用此行。{!! $entries->links() !!}或{!! $users->render() !!}也在你的为每个,把它改成这个@forelse($entries as $entry)&nbsp; &nbsp; &nbsp;<tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<td> {{ $entry->id }} </td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<td> {{ $entry->name }} </td>&nbsp; &nbsp; &nbsp;</tr>@empty尝试将控制器更改为此。&nbsp; public function index(Request $request)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $entries = entries::where('form_id', '=', $id)->orderBy('id', 'DESC')->paginate(15);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return view('entries.index')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ->with('entries', $entries);&nbsp; &nbsp; }

慕侠2389804

你试过吗?{{ $entries->links() }}更新在你的控制器中,你可以试试这个&nbsp;&nbsp;&nbsp;&nbsp;$users&nbsp;=&nbsp;User::paginate(1);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;dd($users->links(),&nbsp;$users->links());你有同样的错误吗?
打开App,查看更多内容
随时随地看视频慕课网APP