- What is ceddyg/query-builder-repository and how does it differ from Eloquent?
- It is a Laravel package that provides a thin repository base class built on top of the DB::table() fluent query builder. Instead of hydrating Eloquent models, it returns a plain stdClass object or a Collection of them, which uses less memory and is faster when you only need raw data. You keep repository pattern separation in your controllers and services without paying model hydration costs.
- How do I install ceddyg/query-builder-repository?
- Install it with Composer using composer require ceddyg/query-builder-repository. The package ships no service provider magic or configuration files, so installation is essentially just the dependency itself. After that you extend or instantiate the repository base class in your own application code.
- Which Laravel and PHP versions does this package support?
- The declared constraints live in the package's composer.json, so check the illuminate/* and php requirements there before committing. The project has a low release cadence, so its version matrix may lag behind recent Laravel majors. If your Laravel version is not covered, the surface area is small enough that a fork or an internal copy is a cheap option.
- How do I create a repository using this package?
- Typically you extend the package's base repository class, point it at a table, and add your own query methods that call the inherited builder helpers. The public surface is small, so read the source to confirm the exact signatures for get, first, find, and paginate before wiring it into services. Keep custom repositories behind an interface so call sites do not depend on the package directly.
- Why would I return stdClass instead of Eloquent models?
- Eloquent hydration is convenient but costs memory and CPU per row, which matters on large result sets or memory-constrained PHP-FPM workers. If an endpoint only needs to read and output data, stdClass is enough and skips casts, accessors, events, and relationship loading. The trade-off is that stdClass is untyped, so you lose autocompletion and some static analysis safety.
- Does the package support pagination, filtering, and chunking?
- Pagination and filtering are handled through the underlying query builder, and the repository typically exposes helpers such as paginate alongside the standard where methods. Chunking behavior is not documented in the README, so verify it in the source before relying on it for large exports. Anything you can do with DB::table() should be reachable, but confirm the wrappers rather than assuming.
- Is ceddyg/query-builder-repository safe to use in production?
- The technical risk is low because it adds no migrations, middleware, or global state, but maturity risk is real: around eleven stars, a single maintainer, and no visible CI or release cadence. Pin an exact version, review the source yourself, and plan to own or fork the code if upstream goes quiet. It is best introduced on non-critical read endpoints first.
- Can I use it with multiple database connections and transactions?
- The package sits on the query builder, so connection handling depends on how the base class resolves its builder instance. Check the source to confirm it respects your configured connections rather than hardcoding the default one. Transactions should work if you wrap calls in DB::transaction on the same connection, but verify the repository does not open its own.
- Does this package protect against SQL injection?
- Because it wraps the fluent query builder, standard where clauses use parameter binding and are safe. The risk appears if the package exposes raw where or DB::raw style expressions, which pass through unparameterized, so never interpolate user input into those. Audit any raw expression path before exposing it to request data.
- Should I use this package or just call DB::table() directly?
- The package adds a reusable repository abstraction, which helps if you want a consistent data layer and less duplication across controllers. If you only need one or two queries, calling DB::table() directly is simpler and avoids a dependency with a bus factor of one. Many teams evaluate the pattern, then reimplement a small internal base class to get the same performance while owning the code.