PHPackages                             garkavenkov/selector-service - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. garkavenkov/selector-service

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

garkavenkov/selector-service
============================

Service for selecting data in Laravel

v0.7.0(2y ago)042MITPHP

Since Jun 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/garkavenkov/laravel-selector-service)[ Packagist](https://packagist.org/packages/garkavenkov/selector-service)[ RSS](/packages/garkavenkov-selector-service/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (12)Used By (0)

selector-service
================

[](#selector-service)

**SelectorService** - Service for selecting date from API

Installation
------------

[](#installation)

Use [Composer](https://getcomposer.org "Composer")

> composer require garkavenkov/selector-service

Usage
-----

[](#usage)

### Initialization

[](#initialization)

In model contoroller create (or add if method allready exists) \_\_construct.

```
use Garkavenkov\Laravel\SelectorService;

class [ControllerName] extends Controller
{
    protected $selector;

    public function __construct(SelectorService $selector)
    {
        $this->selector = $selector;
    }

    public function index()
    {
        $data = $this->selector->get([ModelClass]::class);

        return $data;
    }

    ...
}
```

In \[ModelClass\] add protected static array containing model's allowed fields for data selection and function

```
class [ModelClass] extends Model
{
    use HasFactory;

    protected static $filterable = [
        'id',
        'name',
        ...

    ];

    ...

    public static function getFilterableFields()
    {
        return self::$filterable;
    }
}
```

All condition passed through the query string

where
-----

[](#where)

For example:

>

Return records from table in which field **name** has value **John**

It is also possible to select data for several coditions

>

Return records from table in which **John** is **20** years old

---

per\_page
---------

[](#per_page)

For pagination data, pass **per\_page** parameter with records count per page

> [http://localhost:8000/api/people?per\_page=10](http://localhost:8000/api/people?per_page=10)

Return first 10 records

---

page
----

[](#page)

If parameter **per\_page** was sent, it is passible to pass **page** parameter.

> [http://localhost:8000/api/people?per\_page=10&amp;page=2](http://localhost:8000/api/people?per_page=10&page=2)

Return records start from **11** till **20**

---

with
----

[](#with)

If model has relationship, it is possible to return record(s) with relationship data.

For expamle:

Model **Person** has relationship **address**

> [http://localhost:8000/api/people?where=name=John&amp;with=address](http://localhost:8000/api/people?where=name=John&with=address)

Return **Person** collection(s) with relationship

It is possible to use several relationships

> [http://localhost:8000/api/people?where=name=John&amp;with=address,hobbies](http://localhost:8000/api/people?where=name=John&with=address,hobbies)

---

sort
----

[](#sort)

For sorting result add parameter **sort**

> [http://localhost:8000/api/people?where=name=John&amp;with=address&amp;sort=age](http://localhost:8000/api/people?where=name=John&with=address&sort=age)

Result will be sorting on field **age** ascending For descending sorting use symbol **-** before field name

> [http://localhost:8000/api/people?where=name=John&amp;with=address&amp;sort=-age](http://localhost:8000/api/people?where=name=John&with=address&sort=-age)

It is also possible sorting on several fields

> [http://localhost:8000/api/people?where=name=John&amp;sort=-age,hight](http://localhost:8000/api/people?where=name=John&sort=-age,hight)

---

scope
-----

[](#scope)

It is also possible select data with scope

> [http://localhost:8000/api/people?where=name=John&amp;scope=programmer](http://localhost:8000/api/people?where=name=John&scope=programmer)

Return all persons for scope **programmer** and then with name **John**

Of course it's possible to use several scopes

> [http://localhost:8000/api/people?where=name=John&amp;scope=programmer,php](http://localhost:8000/api/people?where=name=John&scope=programmer,php)

---

random
------

[](#random)

>

Return **N** random record

---

fields
------

[](#fields)

It is possible to select particular fields form the record

> [http://localhost:8000/api/people?where=name=John&amp;fields=id,name,age](http://localhost:8000/api/people?where=name=John&fields=id,name,age)

Return only fields **id**, **name**, **age**

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~108 days

Recently: every ~256 days

Total

11

Last Release

753d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d8dec7c047130aa35c0dc054df1af7a0833c2f2fbb3cd9c89011149eea1efa58?d=identicon)[garkavenkov](/maintainers/garkavenkov)

---

Top Contributors

[![garkavenkov](https://avatars.githubusercontent.com/u/10245674?v=4)](https://github.com/garkavenkov "garkavenkov (14 commits)")

### Embed Badge

![Health badge](/badges/garkavenkov-selector-service/health.svg)

```
[![Health](https://phpackages.com/badges/garkavenkov-selector-service/health.svg)](https://phpackages.com/packages/garkavenkov-selector-service)
```

###  Alternatives

[eo/passbook

iOS Passbook for PHP

2681.6M3](/packages/eo-passbook)[sylius/refund-plugin

Plugin provides basic refunds functionality for Sylius application.

701.8M20](/packages/sylius-refund-plugin)[typo3/minimal

Minimal required set of TYPO3 extensions

253.4M84](/packages/typo3-minimal)[marineusde/larapex-charts

Package to provide easy api to build apex charts on Laravel

1222.1k](/packages/marineusde-larapex-charts)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
