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. Just call filter() on a model query, then let clients apply complex conditions via URL query parameters (e.g., filters[title][$contains]=...). Great for clean, flexible APIs.

View on GitHub
Deep Wiki
Context7

title: Allowed Fields description: Learn how to filter data in Laravel Purity. prev: text: 'Relation Fields' link: '/advanced/relation' next: text: 'Livewire' link: '/advanced/livewire'

Allowed Fields

By default, Purity allows every database column and all model relations (that have a defined return type) to be filtered.

// App\Models\User

public function posts(): Illuminate\Database\Eloquent\Relations\HasMany // This is mandatory
{
    return $this->hasMany(Post::class);
}

you can overwrite the allowed columns as follows:

// App\Models\User

protected $filterFields = [
  'email',
  'mobile',
  'posts', // relation
];
    
protected $sortFields = [
  'name',
  'mobile',
];

any field other than email, mobile, or posts will be rejected when filtering.

Overwrite Allowed Fields

to overwrite allowed fields in the controller add filterFields or sortFields before calling filter or sort method.

Post::filterFields('title', 'created_at')->filter()->get();

Post::sortFields('created_at', 'updated_at')->sort()->get();

::: tip filterFields and sortFields 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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony