در حال بارگذاری ...

Pagination Updates Overview0:00

All right, next up, we're going to review some of the pagination changes. Now, as you'll find on the outside, the API will still feel very similar to you. However, when you do need to drill down and edit these Blade files that build up the HTML for your pagination, it's going to be so much easier now versus how it was even a couple releases ago. And, in fact, it's going to feel very similar to the Laravel 3.0 days, which is pretty neat. All right, so let's build up something to paginate. Let's load like a users file, and then we'll pass through. Let's grab the users and paginate them into sets of four. Okay.

Paginating Users in Blade0:36

Let's grab the users and paginate them into sets of four. Okay. So, let's go ahead and create that, resources/views/users.blade.php. And we'll just put this here. Why don't we pull in our app.css file that Laravel includes out of the box. And then we'll say, how about this? For each users as user, spit it out within a list item, you know, just something like that. So, if we were to view this in the browser, it's right up here in the corner. But sure enough, we do see the items, but still no pagination.

Exploring Paginator Views1:29

So, now, yeah, it takes so little work to have pagination in Laravel. And this is nothing new. It's always been this way. However, here's the cool part. Let's say you want to change this. You want to drill down, and you need to alter the makeup of it. Okay. We'll take a look at this. If we were to go to the paginator components, and we look for some Blade files, we can see that there are four.

Publishing Pagination Templates1:45

If we were to go to the paginator components, and we look for some Blade files, we can see that there are four. So, we have Blade files for bootstrap3, bootstrap4, and then, of course, the simplified versions that will just have a next and previous button. But if you were to go to Laravel 5.2 and to the paginator, yeah, there were no Blade files that you could edit or publish. So let's try this. We're going to go to php artisan vendor:publish, and it's going to take those Blade files I just showed you and publish them to your resources/views/vendor directory. So now, if we were to come back, resources, views, pagination, and here are those four.

just showed you and publish them to your resources/views/vendor directory. So now, if we were to come back, resources, views, pagination, and here are those four files. Now, Bootstrap four is still in alpha. It's been that way for a while. So we will stick with Bootstrap three. And now here's the makeup of it. You can modify this however you want. You'll notice that the API is nice and clean, like on firstPage, or does the Paginator have more pages?

Customizing Pagination Markup3:05

Or if we want to come back, yeah, we could change these up here. I think we want 8701 for a left arrow. Give it a refresh. Yeah, you get the basic idea. So on the condition that you need to modify the HTML for your pagination, well, now, yeah, it couldn't be simpler. So either stick with the defaults or run php artisan vendor:publish and then edit the corresponding view file and you're good to go. Pretty great.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟