1"use strict";(self.webpackChunkfirestore_eloquent=self.webpackChunkfirestore_eloquent||[]).push([[1828],{9698:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>o,default:()=>u,frontMatter:()=>s,metadata:()=>i,toc:()=>l});var r=n(5893),a=n(1151);const s={sidebar_position:4},o="Create Document",i={id:"guide/eloquent/create",title:"Create Document",description:"`create()`",source:"@site/versioned_docs/version-2.x/guide/eloquent/create.mdx",sourceDirName:"guide/eloquent",slug:"/guide/eloquent/create",permalink:"/docs/2.x/guide/eloquent/create",draft:!1,unlisted:!1,editUrl:"https://github.com/FreddyWhest/firestore-eloquent-docs/tree/main/versioned_docs/version-2.x/guide/eloquent/create.mdx",tags:[],version:"2.x",sidebarPosition:4,frontMatter:{sidebar_position:4},sidebar:"tutorialSidebar",previous:{title:"Updating data",permalink:"/docs/2.x/guide/eloquent/updating-data"},next:{title:"Deleting Documents",permalink:"/docs/2.x/guide/eloquent/deleting-data"}},d={},l=[{value:"<code>create()</code>",id:"create",level:2},{value:"Parameters",id:"parameters",level:3},{value:"Usage",id:"usage",level:3},{value:"Examples",id:"examples",level:3}];function c(e){const t={code:"code",h1:"h1",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{id:"create-document",children:"Create Document"}),"\n",(0,r.jsx)(t.h2,{id:"create",children:(0,r.jsx)(t.code,{children:"create()"})}),"\n",(0,r.jsxs)(t.p,{children:["The ",(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"create()"})})," method allows you to add new documents to your Firestore collection. It is a powerful and flexible way to insert data into the database while adhering to the specified model rules and configurations."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"create(array $data)"})})}),"\n",(0,r.jsx)(t.h3,{id:"parameters",children:"Parameters"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.code,{children:"$data"})})," (array) - The data to be inserted into the database. The data must be an associative array with the keys being the field names and the values being the field values. The data must adhere to the model rules and configurations."]}),"\n"]}),"\n",(0,r.jsx)(t.h3,{id:"usage",children:"Usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-php",children:"$newUser = User::create(['name' => 'John', 'age' => 20]);\n"})}),"\n",(0,r.jsx)(t.h3,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-php",children:"$newUser = User::create(['name' => 'John', 'age' => 20]);\r\necho $newUser->data()->name; //Result: John\r\n\r\n//Delete the newly created user\r\n$newUser->delete();\n"})})]})}function u(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>o});var r=n(7294);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.