1 month ago

Paging in lenses in Laravel Nova

Posted 1 month ago by JimCZE007

Hi guys, I have this query in Laravel Nova lense:

 ->selectRaw('companies.id, companies.title, companies.city, companies.country, companies.currency_id, total = IsNull(s1.price, 0) + IsNull(s2.price, 0)')
 ->join('pcolicenses as s1', 'companies.pcolicense_id', '=', 's1.id', 'left outer')
 ->join('premiumservices as s2', 'companies.premiumservice_id', '=', 's2.id', 'left outer')
 ->where('companies.currency_id', '1')
 ->orderby('total', 'desc')
 ->orderby('companies.title', 'asc')

Everything OK, but in the second page of list I get error - invalid column name total.

I tried to set different perPageOptions on resource and on lense (to avoid paging in lense), but it works only after page reload, since the frontend is generated by VueJS...

    * The pagination per-page options configured for this resource.
    * @return array
    public static function perPageOptions()
        if(strpos($_SERVER['REQUEST_URI'], 'lens') !== false) {
            return [200];
        } else {
            return [25, 50, 100];

I know, computed fields are problematic, especially in sorting, but how can I get rid of this error, please?

Please sign in or create an account to participate in this conversation.