We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0b810e7 commit 50032faCopy full SHA for 50032fa
src/Jenssegers/Mongodb/Schema/Builder.php
@@ -115,6 +115,23 @@ public function create($collection, Closure $callback = null)
115
}
116
117
118
+ /**
119
+ * Get the first record matching the attributes or create it.
120
+ *
121
+ * @param array $attributes
122
+ * @return \Illuminate\Database\Eloquent\Model
123
+ */
124
+ public function firstOrCreate(array $attributes)
125
+ {
126
+ if (! is_null($instance = $this->where($attributes)->first())) {
127
+ return $instance;
128
+ }
129
+
130
+ $instance = $this->create($attributes);
131
132
133
134
135
/**
136
* Drop a collection from the schema.
137
*
0 commit comments