Download the PHP package raqmeyat/smart-orm without Composer
On this page you can find all versions of the php package raqmeyat/smart-orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download raqmeyat/smart-orm
More information about raqmeyat/smart-orm
Files in raqmeyat/smart-orm
Package smart-orm
Short Description Request-driven smart field selection and smart filters for Eloquent, with data-class and filter generators. Laravel 13+, PHP 8.4+, SQLite / MySQL / PostgreSQL.
License MIT
Homepage https://github.com/loai-k/smart-orm
Informations about the package smart-orm
raqmeyat/smart-orm
Request-driven smart field selection, smart filters and typed data classes for Eloquent. Built for mobile-first JSON APIs: clients ask for exactly the columns and rows they need, the server only ever honours an explicit allow-list.
- Laravel 13+, PHP 8.4+
- SQLite, MySQL / MariaDB and PostgreSQL (schema introspection and
LIKEbehaviour are driver-aware) - Two generators:
make:data-model {model}andmake:filtter {model}
The service provider is auto-discovered. Optional publishing:
1. Smart fetch: select only what you need
Add the trait (or HasSmartOrm, which bundles both traits):
| Request | SQL columns |
|---|---|
?fields=title,views |
posts.title, posts.views, posts.id |
?fields=* |
posts.* (hidden attributes still never serialise) |
(no fields) |
posts.* by default, or the fillable list, see config |
?fields[posts]=title |
JSON:API style, also supported |
What is selectable: the model's $fillable, minus anything in $hidden, plus the primary key (and any
extra_selectable columns from config). Requested names are intersected with that list, so column names never
come from user input verbatim. Override per model:
Unknown fields are ignored by default (fields.strict = false). That is deliberate: an old mobile build that
still asks for a column you removed must not break during a rolling deploy. Turn strict on to get a 422.
smartSelect() keeps expression columns that are already on the query (withCount, selectSub), so order does
not matter.
2. Smart filters
Generate an allow-list from the table schema, then review it:
Request grammar
| Request | Meaning |
|---|---|
?filter[title]=Laravel |
equals |
?filter[title][like]=lara |
contains (case-insensitive on every driver, wildcards escaped) |
?filter[title][starts]=PHP / [ends]=tips |
starts / ends with |
?filter[views][gte]=10&filter[views][lte]=99 |
several operators on one field (AND) |
?filter[views][between]=5,10 |
inclusive range |
?filter[id][in]=1,2,3 or ?filter[id][]=1&filter[id][]=2 |
in list (nin = not in) |
?filter[published_at][null]=1 |
IS NULL (0 = IS NOT NULL; notnull is the inverse) |
?filter[author.name]=Alice |
through a relation |
?filter[search]=hooks |
a custom filter (see below) |
?sort=-views,title |
descending views, then ascending title |
Operators: eq neq gt gte lt lte like starts ends in nin between null notnull.
Custom filters
Safety properties
- Allow-list only. Fields, operators and sort columns not declared in the Filter respond
422(filters.strict). Unlike fields, silently ignoring a filter would return more data than requested. - No raw input in SQL. Column names come from the Filter; values are bound parameters.
LIKEterms are escaped, so%and_match literally. PostgreSQL usesILIKEto match the case-insensitive default of SQLite/MySQL.- Values are cast from the model's
$casts(orFilter::casts()): booleans, integers, dates and enums bind identically on all three databases ("true"against a MySQLtinyintwould otherwise compare as0). - Limits:
max_filters,max_sorts,max_in_values. neqcompiles to<>, which, as in SQL, does not matchNULLrows. Combine withnullif you need them.
Errors render themselves as JSON:
3. Data classes
reads the real table schema and your $casts and writes App\Data\PostData:
partial() is the mobile payload path: unselected columns are absent, not null, and every value is typed:
fromModel() on a partially loaded model throws DataHydrationException naming the missing attributes, so a
half-loaded object can never masquerade as a full one.
Type mapping: integers → int, floats → float, decimals → string (a float would round money),
booleans (incl. tinyint(1)) → bool, dates → CarbonImmutable, JSON / array casts → array, backed-enum casts
→ the enum, everything else textual → string. Hidden attributes are skipped unless --with-hidden.
property_case = camel in config emits camelCase properties.
Generator options
| Command | Options |
|---|---|
make:data-model {model} |
--with-hidden, --force |
make:filtter {model} |
--only-fillable, --force |
{model} accepts User, Billing/Invoice or a fully qualified class. Output goes to App\Data / App\Filters
(configurable), mirroring the model's sub-namespace. Existing files are never overwritten without --force.
Generated filters never include hidden, JSON, long-text or unknown-typed columns, but review them: the
generator cannot know which non-hidden columns are sensitive.
Configuration
See config/smart-orm.php; every option is documented inline.
Testing
CI runs the suite on PHP 8.4 and 8.5, SQLite, MySQL 8.0 / 8.4 and PostgreSQL 16 / 17.
Publishing to Packagist
- Push this directory to GitHub as
raqmeyat/smart-orm(the package name israqmeyat/smart-orm). - Tag a release:
git tag v1.0.0 && git push origin v1.0.0. - Submit the repository URL at https://packagist.org/packages/submit, then enable the GitHub webhook / Packagist GitHub App so new tags are picked up automatically.
Do not add a version key to composer.json; Packagist derives versions from git tags.
License
MIT. See LICENSE. By Loai Kanou
All versions of smart-orm with dependencies
ext-json Version *
illuminate/console Version ^13.0
illuminate/contracts Version ^13.0
illuminate/database Version ^13.0
illuminate/http Version ^13.0
illuminate/support Version ^13.0
nesbot/carbon Version ^3.8