Skip to content

[5.4] Ability to pass data to the view when rendering a paginator#17331

Merged
taylorotwell merged 1 commit into
laravel:5.4from
ockle:pagination-view-data
Jan 15, 2017
Merged

[5.4] Ability to pass data to the view when rendering a paginator#17331
taylorotwell merged 1 commit into
laravel:5.4from
ockle:pagination-view-data

Conversation

@ockle

@ockle ockle commented Jan 13, 2017

Copy link
Copy Markdown
Contributor

When rendering pagination with a custom view:

{!! $users->links('custom-view') !!}

this pull request adds the ability to send data to the view:

{!! $users->links('custom-view', ['foo' => 'bar']) !!}

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

What's the use case for this please. Why not use view composers?

@ockle

ockle commented Jan 13, 2017

Copy link
Copy Markdown
Contributor Author

@GrahamCampbell Because view composers don't contain any relation to the context the view is being rendered in.
As I see it, rendering the pagination is akin to including sub-views. They allow extra data to be passed in so that you can e.g. conditionally show HTML/data/etc.
This functionality would be useful in the pagination view so one could e.g. change the arrow character used for the paginaiton next/previous links in different parts of your application. If you currently want to be able to do this, you have to have two almost identical pagination views that are only different by two characters. This is a significant amount of code repetition.
There is also a suggestion of a convention in the framework that when you specify a view name, the next parameter is data to be passed to the view, so to me, this functionality is one of those rare times in Laravel where you expect something to work the way you are used to but doesn't, so this PR increases consistency in that regard.

@Francismori7

Copy link
Copy Markdown
Contributor

Also might find usage for this by using ['minimalist' => true] which could, in your custom template, prevent some stuff from being outputted.

@taylorotwell taylorotwell merged commit 925a4ac into laravel:5.4 Jan 15, 2017
@tillkruss

Copy link
Copy Markdown
Contributor

Can you add this to the docs, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants