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: Relation Fields prev: text: 'Rename Fields' link: '/advanced/rename' next: text: 'Allowed Fields' link: '/advanced/allowed'

Relation Fields

In this section, we're going to talk about how Purity can help you handle relation fields.

Filtering by Relation

First, you need to define the relation in your model:

use Illuminate\Database\Eloquent\Relations\HasMany;

class Post extends Model
{
use Filterable;

    public function tags(): HasMany
    {
        return $this->hasMany(Tag::class);
    }
}

Note that Purity read available fields from related models, you'll want to edit the $filterFields property in the related model. read more about $filterFields in allowed fields section.

class Tags extends Model
{
use Filterable;

    protected $filterFields = [
        'title',
    ];
}

Now you're all set to apply relation filtering! You can find some examples on the filter examples page.

Sorting by Relation

Purity supports sorting by the following relationship types:

  • One to One
  • One to Many
  • Many to Many

Just like with filtering, you'll need to define the return type of the relations in your model:

use Illuminate\Database\Eloquent\Relations\HasMany;

class Post extends Model
{
use Sortable;

    public function tags(): HasMany
    {
        return $this->hasMany(Tag::class);
    }
}

Check out the sort examples page for some examples.

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