You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have to add this trait for the ID to generate, can not yet make sure if it works properly - like does it add it to relations, does Mongo get proper ObjectID type when data is inserted.
Code is influenced by HasUuid concern from Laravel 9.x
<?phpuseIlluminate\Support\Str;
useMongoDB\BSON\ObjectId;
trait HasMongoIds
{
/** * Generate a primary MongoID for the model. * * @return void */publicstaticfunctionbootHasMongoIds()
{
static::creating(function (self$model) {
if ($model->getKeyName() === '_id' && !$model->getKey()) {
$model->setAttribute('_id', newObjectID);
}
});
}
}
None of my models seem to generate mongodb IDs anymore. I'm trying to figure out what's happening, but to no avail at the moment.
The text was updated successfully, but these errors were encountered: