marcel158's avatar

Paginator set html style

I have a FacebookPage model, that has many FacebookPosts, that has many FacebookUsers. To retrieve the FacebookUsers from a FacebookPage, I have the following method:

public function users() {
        $this->load('posts.users');
        $users = $this->posts->lists('users');
        $collection = new Collection;
        foreach ($users as $postUser) {
            $collection = $collection->merge($postUser);
        }
        return $collection;
    }

This works. But I cannot do paginate() on it, because it is a collection. This is how I'm doing it right now:

$fbpage = $request->get('fbpage'); // getting the FacebookPage
$fbusers = $fbpage->users(); // getting its FacebookUsers
$page = isset($_GET['page']) && intval($_GET['page']) ? $_GET['page'] : 1; // get page number from url
$users = $fbusers->sortByDesc('count')->forPage($page, 15); // get 15 results from current page
$pagination = new \Illuminate\Pagination\Paginator($fbusers->all(), 15, $page); // create bootstrap pagination!
$pagination->setPath($request->getPathInfo()); // set base url for pagination links

This is how far I got. And it's almost perfect! When doing $pagination->render() I'm getting a HTML string

<ul class="pager"><li class="disabled"><span>«</span></li> <li><a href="users?page=2" rel="next">»</a></li></ul>

The pagination works. But I'd like the style from paginate(). I want bootstrap's pagination with page numbers and not just arrows, that do not even look good.

Does someone know how to set the style of \Illuminate\Pagination\Paginator?

0 likes
5 replies
marcel158's avatar

@zachleigh Including a customized paginator template is a great idea and it worked.

@Salomoni but this a better solution. thanks! this is exactly what I was looking for and also expecting from the laravel framework :)

Please or to participate in this conversation.