Refine for Laravel
A package by Hammerstone

Registering Filters

Refine is a paid package. To purchase, head to

In Laravel, when you are creating a polymorphic relationship, you have the opportunity to set up a morphMap. From the Laravel docs:

By default, Laravel will use the fully qualified class name to store the type of the related model. For instance, given the one-to-many example above where a Comment may belong to a Post or a Video, the default commentable_type would be either App\Post or App\Video, respectively.

However, you may wish to decouple your database from your application's internal structure. In that case, you may define a "morph map" to instruct Eloquent to use a custom name for each model instead of the class name:

Which looks like this:

use Illuminate\Database\Eloquent\Relations\Relation;
'posts' => 'App\Post',
'videos' => 'App\Video',

In the same way, when you are stabilizing your filters, Hammerstone will use the fully qualified class name to represent the type of filter that is being stored. This could cause problems in the future should you ever want to rename or move the filter class.

For that reason, it's recommended that you register a filter under a key that is not the class name. You can do that by calling the register method on the base filter. A good place to do this would be in a service provider:

'employees' => EmployeeFilter::class,
Code highlighting powered by, a Hammerstone product.

Now you're free to move or rename the EmployeeFilter class without invalidating all the stored filters you may have.