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 select is used, omit removes the specified fields from the default output.
  • If select is used, omit still 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 omit to remove sensitive fields such as password or authToken.
  • Prefer omit when returning full objects but needing fine control over field removal.
  • If using select, remember that omit still applies and overrides it.
  • Do not use omit for nested fields inside include; it only affects the root model.