Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Purity Laravel Package

abbasudo/laravel-purity

Laravel Purity adds elegant filtering and sorting to Eloquent queries via a simple filter() method. Let frontend users drive complex query conditions using URL query string parameters (e.g., filters[title][$contains]=Purity), with minimal boilerplate.

View on GitHub
Deep Wiki
Context7

title: Rename Fields prev: text: 'Available Methods' link: '/js-examples/available-methods' next: text: 'Relation Fields' link: '/advanced/relation'

Rename Filter Fields

To rename filter fields, you can add a value to fields defined in $renamedFilterFields. This is useful when you want to use a different name for a field in the client-side, while keeping the actual database column name intact.

// App\Models\User

// Example URL: ?filter[phone][$eq]=0000000000

// The $renamedFilterFields property is used to map the client-side field names to the actual database column names.
protected $renamedFilterFields = [
  'mobile' => 'phone', // The actual database column is 'mobile', but the client should use 'phone'.
  'posts'  => 'writing', // The actual relation is 'posts', but the client should use 'writing'.
];

In this case, the client should send phone to filter by the mobile column in the database.

Rename Sort Fields

To rename sort fields, you can add a value to the defined key in $sortFields. This is similar to renaming filter fields, but applies to sorting operations.

// App\Models\User

// Example URL: ?sort=phone

// The $sortFields property is used to map the client-side field names to the actual database column names for sorting.
protected $sortFields = [
  'name',
  'mobile' => 'phone', // The actual database column is 'mobile', but the client should use 'phone' for sorting.
];

In this case, the client should send phone to sort by the mobile column in the database.

Overwrite Renamed Fields

Overwrite Renamed Fields To overwrite renamed fields in the controller; you can pass renamed fields to rebamedFilterFields and sortFields.

// Overwriting the renamed filter fields in the controller.
Post::renamedFilterFields(['created_at' => 'published_date'])->filter()->get();

// Overwriting the sort fields in the controller.
Post::sortFields([
    'created_at' => 'published_date',
    'updated_at'
  ])->sort()->get();

::: tip Note that sortFields and renamedFilterFields will overwrite fields defined in the model. :::

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport