PageSourceSearch

https://firestore-eloquent.netlify.app/assets/js/2f92d79a.1eb50a8f.js

js firestore-eloquent.netlify.app collected 2026-10-03 10:45:35 UTC 6,355 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkfirestore_eloquent=self.webpackChunkfirestore_eloquent||[]).push([[8826],{3646:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>r,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>d,toc:()=>c});var i=n(5893),s=n(1151);const o={sidebar_position:5},l="Deleting Documents",d={id:"guide/eloquent/deleting-data",title:"Deleting Documents",description:"Deleting Documents in Firestore Eloquent Library",source:"@site/versioned_docs/version-1.x/guide/eloquent/deleting-data.mdx",sourceDirName:"guide/eloquent",slug:"/guide/eloquent/deleting-data",permalink:"/docs/1.x/guide/eloquent/deleting-data",draft:!1,unlisted:!1,editUrl:"https://github.com/FreddyWhest/firestore-eloquent-docs/tree/main/versioned_docs/version-1.x/guide/eloquent/deleting-data.mdx",tags:[],version:"1.x",sidebarPosition:5,frontMatter:{sidebar_position:5},sidebar:"tutorialSidebar",previous:{title:"Create Document",permalink:"/docs/1.x/guide/eloquent/create"},next:{title:"Relationships",permalink:"/docs/1.x/guide/eloquent/relationships"}},r={},c=[{value:"Deleting Documents in Firestore Eloquent Library",id:"deleting-documents-in-firestore-eloquent-library",level:2},{value:"Delete Many Documents with <code>deleteMany()</code>",id:"delete-many-documents-with-deletemany",level:3},{value:"Basic Deletion",id:"basic-deletion",level:4},{value:"Deletion with Multiple Conditions",id:"deletion-with-multiple-conditions",level:4},{value:"Delete Single Document with <code>delete()</code>",id:"delete-single-document-with-delete",level:3},{value:"Examples",id:"examples",level:4}];function a(e){const t={admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",p:"p",pre:"pre",strong:"strong",...(0,s.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h1,{id:"deleting-documents",children:"Deleting Documents"}),"\n",(0,i.jsx)(t.h2,{id:"deleting-documents-in-firestore-eloquent-library",children:"Deleting Documents in Firestore Eloquent Library"}),"\n",(0,i.jsx)(t.p,{children:"Deleting documents in Firestore is an essential operation, and the Firestore Eloquent Library in Laravel offers convenient methods to remove documents from a collection. Let's explore how to delete documents using the library's features."}),"\n",(0,i.jsxs)(t.h3,{id:"delete-many-documents-with-deletemany",children:["Delete Many Documents with ",(0,i.jsx)(t.code,{children:"deleteMany()"})]}),"\n",(0,i.jsx)(t.admonition,{type:"warning",children:(0,i.jsx)(t.p,{children:"Deleting many documents in a collection can take a long time if there are a lot of documents in the sub collection."})}),"\n",(0,i.jsxs)(t.p,{children:["The ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"deleteMany()"})})," method allows you to delete multiple documents in a Firestore collection based on a specified query. You can use this method to delete documents that match certain conditions."]}),"\n",(0,i.jsx)(t.h4,{id:"basic-deletion",children:"Basic Deletion"}),"\n",(0,i.jsxs)(t.p,{children:["Let's say we want to delete all documents in the ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"users"})})," collection that have the ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"age"})})," field set to ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"18"})}),". We can use the ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"deleteMany()"})})," method to delete all documents that match this condition."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-php",children:"// Delete all users with age 20\r\nUser::where(['age', '=',  20])->deleteMany();\n"})}),"\n",(0,i.jsx)(t.h4,{id:"deletion-with-multiple-conditions",children:"Deletion with Multiple Conditions"}),"\n",(0,i.jsxs)(t.p,{children:["You can also delete documents that match multiple conditions. Let's say we want to delete all users with the ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"age"})})," field set to ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"20"})})," and the ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"name"})})," field set to ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"John"})}),". We can use the ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"deleteMany()"})})," method to delete all documents that match this condition."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-php",children:"// Delete all users with age 20 and name John\r\nUser::andWhere(['age', '=',  20], ['name', '=', 'John'])->deleteMany();\n"})}),"\n",(0,i.jsxs)(t.h3,{id:"delete-single-document-with-delete",children:["Delete Single Document with ",(0,i.jsx)(t.code,{children:"delete()"})]}),"\n",(0,i.jsxs)(t.p,{children:["The ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"delete()"})})," method allows you to delete a single document in a Firestore collection. You can use this method to delete a document that matches a certain condition."]}),"\n",(0,i.jsx)(t.h4,{id:"examples",children:"Examples"}),"\n",(0,i.jsxs)(t.p,{children:["Let's say we want to delete a user with the ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"age"})})," field set to ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"20"})}),". We can use the ",(0,i.jsx)(t.strong,{children:(0,i.jsx)(t.code,{children:"delete()"})})," method to delete the document that matches this condition."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-php",children:"// Delete a user with the specified ID\r\n$user = User::where(['user_id', '=', $userId])->first();\r\n$user->delete();\n"})}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-php",children:"// Delete a user with the specified ID\r\n$user = User::where(['user_id', '=', $userId])->firstOrFail();\r\n$user->delete();\n"})})]})}function h(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},1151:(e,t,n)=>{n.d(t,{Z:()=>d,a:()=>l});var i=n(7294);const s={},o=i.createContext(s);function l(e){const t=i.useContext(o);return i.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),i.createElement(o.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.