atannex/retrive
Atannex Retrive is a lightweight Laravel/PHP package that streamlines data retrieval with a clean, expressive API. It helps developers fetch, filter, and organize records quickly while keeping application code readable and maintainable.
atannex/retrive is a data-retrieval layer that sits on top of Eloquent. Instead of scattering query scopes, when() clauses, and with() calls across controllers, you describe what a resource exposes once and let the package resolve the query. Install it and confirm the platform requirements first — PHP 8.3+ and Laravel 11 or 12 only. On older stacks, stop here; there is no backport path.
composer require atannex/retrive
Then, in order:
php artisan vendor:publish) and check whether caching is enabled by default — that is the setting that will surprise you first in local development.Post or Product. The resource is where you declare filterable attributes, sortable fields, allowed includes, and visibility rules. This is the single file you will return to most often, so treat it as the source of truth for the resource's public surface.Post::retrieve()->filter(...)->sort(...)->include(...)->get(). Verify method names against the README — the retriever's fluent surface is the part most likely to shift between minor versions.The first genuinely valuable use case is a listing endpoint: an index action with request-driven filters, sorts, pagination, and eager-loaded relations. Replacing hand-rolled $request->query('sort') branching with a declared resource is where the package earns its place. Start there, not with the exotic features (neighbours, related records) until the basic listing path is clean.
Magic finders (getPostBySlug, getPostsByCategory) are the lowest-effort win — they give you typed conveniences that read well in controllers and can be adopted incrementally, one call site at a time.
Resource-first, then retrieve. The package's core discipline is that the model stays thin and the resource declares the contract: which columns are filterable, which are sortable, which relations are includable, and who can see what. Resist the urge to also keep hand-written scopes doing the same job — duplicated sources of truth are how visibility bugs appear.
Request-driven filters as the default for index endpoints. The intended pattern is to pass the request through to the retriever and let the resource's declarations act as an allowlist. This is the package's biggest ergonomic gain and its biggest trust boundary: the resource declaration is your input validation. Be explicit about it, and add feature tests that assert an unexpected query parameter is ignored rather than applied.
Visibility rules belong in the resource, not the controller. Anything like "drafts only visible to authors and editors," "prices hidden for guests," or "soft-deleted rows excluded except for admins" should be declared once. Be careful that magic finders honour those rules — verify this with a test, because a convenient finder that bypasses visibility is the worst possible footgun.
Compose the fluent chain, but keep it shallow. A retrieval chain of filter → sort → include → search is readable; a twelve-call chain spread across a controller, a service, and a middleware is not. If a chain grows, wrap it in a named method on the resource or a small application-level query object, so the intent survives.
Caching is self-invalidating — so lean on it, and test it. The promise here is that cached retrieval results are invalidated when the underlying models change. Use it for read-heavy listing pages and search results, but write one integration test per resource that (a) retrieves, (b) mutates the model, (c) retrieves again and asserts freshness. This is the single most important test class for a package that owns your cache keys, because a silent staleness bug is nearly invisible in development.
Hierarchy-aware relation filters are for trees, not general filtering. If you have categories, folders, org units, or comments with parent/child structure, use the hierarchy filters rather than hand-rolling recursive CTE logic. Keep the recursion scoped to genuinely finite trees and add a depth cap in your resource if the data model permits pathological nesting.
Neighbours and related records are for detail pages. "Previous/next post," "other products in this collection," "similar articles" are the intended consumers. These are usually the last features you adopt and the ones most likely to need caching, since they tend to fire on your highest-traffic pages.
Integrate at the boundary you already have. For an API, the retriever's output can feed your existing API Resource / transformer classes — don't let the package dictate your response shape. For Blade-rendered pages, use the retriever for the data and keep pagination rendering in the framework's standard paginator.
composer why-not before promising it to a legacy codebase; the constraint may cascade into your other dependencies.v1.0.0 is the first stable release. The API is now something you can build against, but expect the README to be the authoritative reference — earlier 0.x usage examples circulating online may not match.getPostsByCategory. Expect occasional guesswork about pluralisation, nesting, and argument order, and expect naming collisions with your own model methods. Prefer explicit retriever calls in code that other people will maintain, and treat finders as sugar for straightforward cases.DB::listen or Laravel Telescope that an include('comments.user') produces two queries, not N+1. A retrieval layer that names relations is not the same as one that eager-loads them correctly.updateQuietly(), DB::table() bulk updates, and raw SQL all bypass Eloquent model events and therefore may bypass invalidation. If you mutate outside Eloquent, assume the cache is stale and invalidate manually or clear on deploy.LIKE '%term%' will not scale and will not use indexes. Check what the package generates (toSql() on the retrieval, or Telescope) and add appropriate indexes — or a real search driver — before shipping to production.How can I help you explore Laravel packages today?