Omit Fields
Exclude specific fields from the returned result using the omit parameter.
Omitting Fields with omit
The omit parameter allows you to exclude specific fields
from the returned data. This is helpful when returning most fields while intentionally hiding
sensitive information such as passwords or tokens.
- Accepts an associative array where each key is the field name and the value is
true. - If no
selectis used,omitremoves the specified fields from the default output. - If
selectis used,omitstill applies and removes matching keys. - Cannot be used to omit fields inside related models included with
include.
Example Usage: Omitting Fields
use Lib\Prisma\Classes\Prisma;
$prisma = Prisma::getInstance();
$users = $prisma->user->findMany([
'omit' => [
'password' => true,
'authToken' => true
]
]);
echo "<pre>";
print_r($users);
echo "</pre>";
Example Usage: Combining select with omit
$users = $prisma->user->findMany([
'select' => [
'id' => true,
'name' => true,
'email' => true,
'password' => true
],
'omit' => [
'password' => true
]
]);
Best Practices
- Use
omitto remove sensitive fields such aspasswordorauthToken. - Prefer
omitwhen returning full objects but needing fine control over field removal. - If using
select, remember thatomitstill applies and overrides it. - Do not use
omitfor nested fields insideinclude; it only affects the root model.