-
Notifications
You must be signed in to change notification settings - Fork 1.5k
-
- Laravel-mongodb Version: 8.34.0
- PHP Version: 8.0
- Database Driver & Version: 3.8
I have 2 models, Product and Vendor. when I want to create a new product, I need to embed existing vendor to my new product. so far, this is what I have done:
$vendor = Vendor::find($request->vendor);
$product = Product::create([
'name'=>$request->name
'vendor'=>$vendor
]);
that code resulting the following document
{
"_id": "606ffac287be2020b968c613",
"name": "product name",
"vendor": {
"incrementing": true,
"exists": true,
"wasRecentlyCreated": false,
"timestamps": true
},
"updated_at": "2021-04-09T06:57:06.032000Z",
"created_at": "2021-04-09T06:57:06.032000Z"
},
so, what is the correct way to embed existing document into newly created document?
PS: I also tried to save the vendor just like the documentation said, that is:
$product->vendor()->save($vendor)
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment