@@ -23,50 +23,88 @@ an Eloquent model or query builder.
2323To insert a document, pass the data you need to insert as a document containing
2424the fields and values to the ``create()`` method.
2525
26- Example
27- -------
28-
29- This usage example performs the following actions:
30-
31- - Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the
32- ``sample_mflix`` database
33- - Inserts a document into the ``movies`` collection
34-
35- The example calls the ``create()`` method to insert a document that contains the following
36- information:
37-
38- - ``title`` value of ``"Marriage Story"``
39- - ``year`` value of ``2019``
40- - ``runtime`` value of ``136``
41-
42- .. io-code-block::
43- :copyable: true
26+ .. tip::
4427
45- .. input:: ../includes/usage-examples/InsertOneTest.php
46- :start-after: begin-insert-one
47- :end-before: end-insert-one
48- :language: php
49- :dedent:
28+ You can also use the ``save()`` or ``insert()`` methods to insert a
29+ document into a collection. To learn more about insert operations,
30+ see the :ref:`laravel-fundamentals-insert-documents` section of the
31+ Write Operations guide.
5032
51- .. output::
52- :language: json
53- :visible: false
33+ Example
34+ -------
5435
55- {
56- "title": "Marriage Story",
57- "year": 2019,
58- "runtime": 136,
59- "updated_at": "...",
60- "created_at": "...",
61- "_id": "..."
62- }
36+ Select from the following :guilabel:`Eloquent` and :guilabel:`Query
37+ Builder` tabs to view usage examples for the same operation that use
38+ each corresponding query syntax:
39+
40+ .. tabs::
41+
42+ .. tab:: Eloquent
43+ :tabid: eloquent-model-count
44+
45+ This example performs the following actions:
46+
47+ - Uses the ``Movie`` Eloquent model to represent the ``movies``
48+ collection in the ``sample_mflix`` database
49+ - Inserts a document into the ``movies`` collection
50+
51+ The example calls the ``create()`` method to insert a document
52+ that contains the following fields and values:
53+
54+ - ``title`` value of ``"Marriage Story"``
55+ - ``year`` value of ``2019``
56+ - ``runtime`` value of ``136``
57+
58+ .. io-code-block::
59+ :copyable: true
60+
61+ .. input:: ../includes/usage-examples/InsertOneTest.php
62+ :start-after: begin-eloquent-insert-one
63+ :end-before: end-eloquent-insert-one
64+ :language: php
65+ :dedent:
66+
67+ .. output::
68+ :language: console
69+ :visible: false
70+
71+ {
72+ "title": "Marriage Story",
73+ "year": 2019,
74+ "runtime": 136,
75+ "updated_at": "...",
76+ "created_at": "...",
77+ "_id": "..."
78+ }
79+
80+ .. tab:: Query Builder
81+ :tabid: query-builder-count
82+
83+ This example performs the following actions:
84+
85+ - Accesses the ``movies`` collection by calling the ``table()``
86+ method from the ``DB`` facade
87+ - Inserts a document into the ``movies`` collection
88+
89+ The example calls the ``create()`` method to insert a document
90+ that contains the following fields and values:
91+
92+ - ``title`` value of ``"Marriage Story"``
93+ - ``year`` value of ``2019``
94+ - ``runtime`` value of ``136``
95+
96+ .. io-code-block::
97+
98+ .. input:: ../includes/usage-examples/InsertOneTest.php
99+ :start-after: begin-qb-insert-one
100+ :end-before: end-qb-insert-one
101+ :language: php
102+ :dedent:
103+
104+ .. output::
105+ :language: console
106+ :visible: false
107+
108+ Insert operation success: yes
63109
64110.. include:: /includes/usage-examples/fact-edit-laravel-app.rst
65-
66- .. tip::
67-
68- You can also use the ``save()`` or ``insert()`` methods to insert a document into a collection.
69- To learn more about insert operations, see the :ref:`laravel-fundamentals-insert-documents` section
70- of the Write Operations guide.
71-
72-
0 commit comments