whitecube / nova-page

Static pages content management for Laravel Nova
https://whitecube.github.io/nova-page
MIT License
238 stars 41 forks source link

Added novaPageIndexQuery to StaticResource to mimic indexQuery #46

Open GarethSomers opened 4 years ago

GarethSomers commented 4 years ago

I've added a method novaPageIndexQuery to Whitecube\NovaPage\Pages\StaticResource which allows someone to manipulate the Whitecube\NovaPage\Pages\Query on the nova index page. It's intended to mimic the indexQuery method.

I've also added the methodWhitecube\NovaPage\Pages\Query::sortBy to allow simple sorting.

It might work better just having a generic callback (e.g. $query->setCallback(...)) which gets applied to the Collection in Whitecube\NovaPage\Pages\Query::get.

~Should merge in conjunction with https://github.com/whitecube/nova-page/pull/45~ merged

Closes

https://github.com/whitecube/nova-page/issues/44 (sorta)

Usage

Configure your own config novapage.default_page_resource in config/novapage.php

    'default_page_resource' => \App\Nova\Page::class,
<?php

namespace App\Nova;

use Whitecube\NovaPage\Pages\PageResource;
use Whitecube\NovaPage\Pages\Query;

class Page extends PageResource
{
    public static function novaPageIndexQuery(Query $query)
    {
        return $query->orderBy(function ($item) {
            return $item->getTitle();
        }, 'ASC');
    }
}