Refine for Laravel
A package by Hammerstone

Refine for Laravel Nova

Refine is a paid package. To purchase, head to hammerstone.dev.

Installation

To use Refine with Nova, you must first require the package composer require hammerstone/refine-nova. This will install hammerstone/refine-laravel as well.

Modifying the Resource

To use Refine with one of your Nova resources, add the RefinesModels trait to your resource.

class Company extends Resource
{
use RefinesModels;
}

This will require you to implement a single method called refineFilter. From this method you will return the filter class that applies to this resource. (To learn more about creating filters, see the Creating Filters section.)

class Company extends Resource
{
use RefinesModels;
 
public static function refineFilter(NovaRequest $request)
{
// The filter to use for this resource.
return CompanyFilter::class;
}
}
Code highlighting powered by torchlight.dev, a Hammerstone product.

To activate the filtering, you'll need to modify the indexQuery method to hook into the Nova lifecycle:

class Company extends Resource
{
use RefinesModels;
 
public static function indexQuery(NovaRequest $request, $query)
{
// Run this request + query through Refine.
static::refine($request, $query);
}
}

To show the query builder on the frontend, add the Refine card to your cards array.

class Company extends Resource
{
use RefinesModels;
 
public function cards(Request $request)
{
return [
RefineCard::forFilter(static::refineFilter($request))
];
}
}

Configuring the Frontend

Add the following code in a service provider to tell Refine to use the Vue2 frontend.

public function boot()
{
Clause::$resolveComponentUsing = Vue2Frontend::class;
}

Initial Query

When using the Nova integration, the initial query is provided by Nova. Because Nova handles so much authentication, authorization, and showing/hiding of resources, Refine hooks into the Nova request instead of generating its own query.

use Hammerstone\Refine\Filter;
 
class CompanyFilter extends Filter
{
public function initialQuery()
{
// You can leave this blank, it's provided by Nova!
}
 
public function conditions()
{
// @TODO
}
}