The schema constraint can be added during collection creation or updated after: https://www.mongodb.com/docs/manual/core/schema-validation/update-schema-validation/#modify-the-validation-schema.
Laravel Eloquent migrations has a schema feature that is used to create SQL tables, and Collection indexes in the context of MongoDB. We don't want to generate the JSON schema from the Eloquent schema builder methods (string, increment...) https://laravel.com/docs/12.x/migrations#migration-structure
Add a new method Blueprint::jsonSchema() that updates the JSON schema of the collection.
Usage:
Schema::create('flights', function (Blueprint $collection) { $collection->jsonSchema([ 'bsonType' => 'object', 'required' => [ 'username', 'password' ], 'properties' => [ 'username' => [ 'bsonType' => 'string', 'description' => 'must be a string and is required', ], 'password' => [ 'bsonType' => 'string', 'minLength' => 8, 'description' => 'must be a string at least 8 characters long, and is required', ] ] ]); });
This feature should be covered by the documentation.
- related to
-
PHPORM-130 Document Laravel migration schema feature
-
- Backlog
-