Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to define metadata when creating a new document #11

Merged
merged 2 commits into from
Mar 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,19 @@ public static function findOrFail(string $key): self
* Save a new model and return the instance.
*
* @param array $attributes
*
* @param string|null $id
* @return static
* @psalm-suppress LessSpecificReturnStatement
*/
public static function create(array $attributes): self
public static function create(array $attributes, ?string $id = null): self
{
$metadata = [];
if (!is_null($id)) {
$metadata['_id'] = $id;
}

return tap(
(new static())->newInstance($attributes),
(new static())->newInstance($attributes, $metadata),
static function ($instance) {
$instance->save();
}
Expand Down