jacquestvanzuydam / laravel-firebird

Firebird Illuminate package for Laravel 5
63 stars 93 forks source link

problems whit paginate method #57

Closed azamudio1971 closed 6 months ago

azamudio1971 commented 6 years ago

i'm using support 5.5. when i want paginate results, laravel return this screens

clip2net_171127212837

clip2net_171127212813

any idea?

azamudio1971 commented 6 years ago

searching in google i find this https://github.com/laravel/framework/issues/18460

How can I solve it without modifying the vendor?

KKSzymanowski commented 6 years ago

Extend the firebird driver and modify it then.

JJS4ntos commented 6 years ago

I'm with a same problem too. Have you any news about it?

JJS4ntos commented 6 years ago

I got it using the simplePagination function! Hope it help you.

igorfaria6 commented 6 years ago

$users = User::all(); $users = $this->paginate($users)->setPath($request->url());

paginate function: protected function paginate($items, $perPage = 12){ $currentPage = LengthAwarePaginator::resolveCurrentPage(); $currentPageItems = $items->slice(($currentPage - 1) * $perPage, $perPage); return new LengthAwarePaginator($currentPageItems, count($items), $perPage); }

try this

mstanarevic commented 6 years ago

Here's my workaround:

Create new file in App\Database\Query\ named FirebirdQueryBuilder.php that has fix in it:

<?php
namespace App\Database\Query;

use Firebird\Query\Builder as BaseBuilder;

class FirebirdQueryBuilder extends BaseBuilder {

    /**
     * AGGREGATE fix
     *
     * Get the count of the total records for the paginator.
     *
     * @param  array  $columns
     * @return int
     */
    public function getCountForPagination($columns = ['*'])
    {
        $results = $this->runPaginationCountQuery($columns);

        // Once we have run the pagination count query, we will get the resulting count and
        // take into account what type of query it was. When there is a group by we will
        // just return the count of the entire results set since that will be correct.
        if (isset($this->groups)) {
            return count($results);
        } elseif (! isset($results[0])) {
            return 0;
        } elseif (is_object($results[0])) {
            return (int) $results[0]->AGGREGATE;
        } else {
            return (int) array_change_key_case((array) $results[0])['aggregate'];
        }
    }
}

Than in your BaseModel.php that extends Firebird\Model override newBaseQueryBuilder() method, and use new FirebirdQueryBuilder that we created:

<?php

namespace App;

use Firebird\Model as Model;
use Illuminate\Http\Request as FormRequest;
use App\Database\Query\FirebirdQueryBuilder as QueryBuilder;

class BaseModel extends Model
{
    /**
     * Get a new query builder instance for the connection.
     *
     * @return \Illuminate\Database\Query\Builder
     */
    protected function newBaseQueryBuilder()
    {
        $connection = $this->getConnection();

        return new QueryBuilder(
            $connection, $connection->getQueryGrammar(), $connection->getPostProcessor()
        );
    }
}

And that's it! Hope it helps. Cheers.

Rachmat96 commented 5 years ago

I still have problem with paginate, Undefined property: stdClass::$aggregate