[{"data":1,"prerenderedAt":661},["ShallowReactive",2],{"navigation_docs":3,"-essentials-builder-scoping":90,"-essentials-builder-scoping-surround":656},[4,25,65],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":6},"Getting Started",false,"\u002Fgetting-started","1.getting-started",[10,15,20],{"title":11,"path":12,"stem":13,"icon":14},"Installation","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F1.installation","i-lucide-download",{"title":16,"path":17,"stem":18,"icon":19},"Quickstart","\u002Fgetting-started\u002Fquickstart","1.getting-started\u002F2.quickstart","i-lucide-rocket",{"title":21,"path":22,"stem":23,"icon":24},"Upgrade Guide","\u002Fgetting-started\u002Fupgrade-guide","1.getting-started\u002F3.upgrade-guide","i-lucide-arrow-up-right",{"title":26,"path":27,"stem":28,"children":29,"page":6},"Essentials","\u002Fessentials","2.essentials",[30,35,40,45,50,55,60],{"title":31,"path":32,"stem":33,"icon":34},"Configuration","\u002Fessentials\u002Fconfiguration","2.essentials\u002F1.configuration","i-lucide-settings",{"title":36,"path":37,"stem":38,"icon":39},"Authorization","\u002Fessentials\u002Fauthorization","2.essentials\u002F2.authorization","i-lucide-lock",{"title":41,"path":42,"stem":43,"icon":44},"Field Types","\u002Fessentials\u002Ffield-types","2.essentials\u002F3.field-types","i-lucide-shapes",{"title":46,"path":47,"stem":48,"icon":49},"Preset Custom Fields","\u002Fessentials\u002Fpreset-custom-fields","2.essentials\u002F4.preset-custom-fields","i-lucide-eye",{"title":51,"path":52,"stem":53,"icon":54},"Import\u002FExport","\u002Fessentials\u002Fimport-export","2.essentials\u002F5.import-export","i-lucide-file-output",{"title":56,"path":57,"stem":58,"icon":59},"Data Model","\u002Fessentials\u002Fdata-model","2.essentials\u002F6.data-model","i-lucide-database",{"title":61,"path":62,"stem":63,"icon":64},"Builder Scoping","\u002Fessentials\u002Fbuilder-scoping","2.essentials\u002F7.builder-scoping","i-lucide-filter",{"title":66,"path":67,"stem":68,"children":69,"page":6},"Community","\u002Fcommunity","3.community",[70,75,80,85],{"title":71,"path":72,"stem":73,"icon":74},"Support","\u002Fcommunity\u002Fsupport","3.community\u002F1.support","i-lucide-life-buoy",{"title":76,"path":77,"stem":78,"icon":79},"Contributing","\u002Fcommunity\u002Fcontributing","3.community\u002F2.contributing","i-lucide-handshake",{"title":81,"path":82,"stem":83,"icon":84},"License","\u002Fcommunity\u002Flicense","3.community\u002F3.license","i-lucide-scale",{"title":86,"path":87,"stem":88,"icon":89},"Code Distribution","\u002Fcommunity\u002Fcode-distribution","3.community\u002F4.code-distribution","i-lucide-git-branch",{"id":91,"title":61,"body":92,"description":649,"extension":650,"links":651,"meta":652,"navigation":653,"path":62,"seo":654,"stem":63,"__hash__":655},"docs\u002F2.essentials\u002F7.builder-scoping.md",{"type":93,"value":94,"toc":643},"minimark",[95,100,130,259,269,278,310,315,348,358,362,372,575,578,611,632,639],[96,97,99],"h2",{"id":98},"onlysections","onlySections()",[101,102,103,104,108,109,108,112,115,116,108,119,122,123,125,126,129],"p",{},"By default, every builder (",[105,106,107],"code",{},"CustomFields::form()",", ",[105,110,111],{},"::infolist()",[105,113,114],{},"::table()",",\n",[105,117,118],{},"::exporter()",[105,120,121],{},"::importer()",") resolves fields for the whole entity type. ",[105,124,99],{},"\nconstrains that resolution to a specific set of ",[105,127,128],{},"custom_field_sections"," rows:",[131,132,137],"pre",{"className":133,"code":134,"language":135,"meta":136,"style":136},"language-php shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","use Relaticle\\CustomFields\\Facades\\CustomFields;\n\nCustomFields::form()\n    ->forModel($model)\n    ->onlySections([$sectionA->id, $sectionB->id])\n    ->build();\n","php","",[105,138,139,171,178,194,212,248],{"__ignoreMap":136},[140,141,144,148,152,156,159,161,164,166,168],"span",{"class":142,"line":143},"line",1,[140,145,147],{"class":146},"sbssI","use",[140,149,151],{"class":150},"sTEyZ"," Relaticle",[140,153,155],{"class":154},"sMK4o","\\",[140,157,158],{"class":150},"CustomFields",[140,160,155],{"class":154},[140,162,163],{"class":150},"Facades",[140,165,155],{"class":154},[140,167,158],{"class":150},[140,169,170],{"class":154},";\n",[140,172,174],{"class":142,"line":173},2,[140,175,177],{"emptyLinePlaceholder":176},true,"\n",[140,179,181,184,187,191],{"class":142,"line":180},3,[140,182,158],{"class":183},"sBMFI",[140,185,186],{"class":154},"::",[140,188,190],{"class":189},"s2Zo4","form",[140,192,193],{"class":154},"()\n",[140,195,197,200,203,206,209],{"class":142,"line":196},4,[140,198,199],{"class":154},"    ->",[140,201,202],{"class":189},"forModel",[140,204,205],{"class":154},"($",[140,207,208],{"class":150},"model",[140,210,211],{"class":154},")\n",[140,213,215,217,220,223,226,229,232,235,238,241,243,245],{"class":142,"line":214},5,[140,216,199],{"class":154},[140,218,219],{"class":189},"onlySections",[140,221,222],{"class":154},"([$",[140,224,225],{"class":150},"sectionA",[140,227,228],{"class":154},"->",[140,230,231],{"class":150},"id",[140,233,234],{"class":154},",",[140,236,237],{"class":154}," $",[140,239,240],{"class":150},"sectionB",[140,242,228],{"class":154},[140,244,231],{"class":150},[140,246,247],{"class":154},"])\n",[140,249,251,253,256],{"class":142,"line":250},6,[140,252,199],{"class":154},[140,254,255],{"class":189},"build",[140,257,258],{"class":154},"();\n",[101,260,261,262,265,266,268],{},"Passing ",[105,263,264],{},"[]"," (the default) means \"no scope\" — existing call sites that never call\n",[105,267,99],{}," are unaffected.",[101,270,271,272,274,275,277],{},"This exists for consumers that version their form definitions — for example, cloning a\nsection (and its fields) per form version. Field codes are normally unique per entity\ntype, so two versions of \"the same field\" would collide on ",[105,273,105],{}," unless resolution is\nscoped by section. ",[105,276,99],{}," lets each version's builder only see its own\nsection(s), so the same code can live in more than one section without one bleeding into\nthe other's schema.",[101,279,280,282,283,286,287,290,291,294,295,290,298,301,302,305,306,309],{},[105,281,99],{}," is inherited by every builder from ",[105,284,285],{},"BaseBuilder",", including through\n",[105,288,289],{},"FormBuilder::build()"," \u002F ",[105,292,293],{},"InfolistBuilder::build()"," — the scope is threaded through\n",[105,296,297],{},"FormContainer",[105,299,300],{},"InfolistContainer"," as well, so it applies whether you call ",[105,303,304],{},"->build()","\nor ",[105,307,308],{},"->values()",".",[311,312,314],"h3",{"id":313},"the-persistence-contract-read-this-before-relying-on-section-scoped-codes","The persistence contract — read this before relying on section-scoped codes",[101,316,317,319,320,324,325,328,329,332,333,337,338,108,340,343,344,347],{},[105,318,99],{}," narrows ",[321,322,323],"em",{},"resolution"," (which fields get loaded onto a form, infolist, or\ntable). It does not change how values are ",[321,326,327],{},"saved",". ",[105,330,331],{},"UsesCustomFields::saveCustomFields()","\niterates the model's custom-field-values relationship and writes each submitted value by\n",[334,335,336],"strong",{},"field code",". If two sections share a code and that relationship isn't scoped to match\n",[105,339,99],{},[105,341,342],{},"saveCustomFields()"," will silently write the same value to ",[334,345,346],{},"both","\nfield rows — a data-corrupting outcome that has nothing to do with whether resolution\nscoping itself is working correctly.",[101,349,350,351,353,354,357],{},"If you use ",[105,352,99],{},", scope your model's custom-field-values relationship\n(",[105,355,356],{},"customFields()"," by default, or your override) to the same section(s). It is\nentity-scoped by default and overridable per model.",[96,359,361],{"id":360},"codegeneratorresolveuniquenessscopeusing","CodeGenerator::resolveUniquenessScopeUsing()",[101,363,364,365,368,369,371],{},"Auto-generated codes (",[105,366,367],{},"FIELD_CODE_AUTO_GENERATE",") are checked for collisions before use.\nRegister a callback to narrow that check the same way ",[105,370,99],{}," narrows\nresolution:",[131,373,375],{"className":133,"code":374,"language":135,"meta":136,"style":136},"use Illuminate\\Database\\Eloquent\\Builder;\nuse Relaticle\\CustomFields\\Support\\CodeGenerator;\n\nCodeGenerator::resolveUniquenessScopeUsing(\n    fn (string $entityType, string $type, int|string|null $sectionId): ?Closure => $sectionId !== null\n        ? fn (Builder $query): Builder => $query->where('custom_field_section_id', $sectionId)\n        : null\n);\n",[105,376,377,401,422,426,438,508,561,569],{"__ignoreMap":136},[140,378,379,381,384,386,389,391,394,396,399],{"class":142,"line":143},[140,380,147],{"class":146},[140,382,383],{"class":150}," Illuminate",[140,385,155],{"class":154},[140,387,388],{"class":150},"Database",[140,390,155],{"class":154},[140,392,393],{"class":150},"Eloquent",[140,395,155],{"class":154},[140,397,398],{"class":150},"Builder",[140,400,170],{"class":154},[140,402,403,405,407,409,411,413,415,417,420],{"class":142,"line":173},[140,404,147],{"class":146},[140,406,151],{"class":150},[140,408,155],{"class":154},[140,410,158],{"class":150},[140,412,155],{"class":154},[140,414,71],{"class":150},[140,416,155],{"class":154},[140,418,419],{"class":150},"CodeGenerator",[140,421,170],{"class":154},[140,423,424],{"class":142,"line":180},[140,425,177],{"emptyLinePlaceholder":176},[140,427,428,430,432,435],{"class":142,"line":196},[140,429,419],{"class":183},[140,431,186],{"class":154},[140,433,434],{"class":189},"resolveUniquenessScopeUsing",[140,436,437],{"class":154},"(\n",[140,439,440,444,447,450,452,455,457,460,462,465,467,470,473,475,477,480,482,485,488,491,494,497,499,502,505],{"class":142,"line":214},[140,441,443],{"class":442},"spNyl","    fn",[140,445,446],{"class":154}," (",[140,448,449],{"class":146},"string",[140,451,237],{"class":154},[140,453,454],{"class":150},"entityType",[140,456,234],{"class":154},[140,458,459],{"class":146}," string",[140,461,237],{"class":154},[140,463,464],{"class":150},"type",[140,466,234],{"class":154},[140,468,469],{"class":146}," int",[140,471,472],{"class":154},"|",[140,474,449],{"class":146},[140,476,472],{"class":154},[140,478,479],{"class":146},"null",[140,481,237],{"class":154},[140,483,484],{"class":150},"sectionId",[140,486,487],{"class":154},"):",[140,489,490],{"class":154}," ?",[140,492,493],{"class":183},"Closure",[140,495,496],{"class":154}," =>",[140,498,237],{"class":154},[140,500,501],{"class":150},"sectionId ",[140,503,504],{"class":154},"!==",[140,506,507],{"class":154}," null\n",[140,509,510,513,516,518,520,522,525,527,530,532,534,536,538,541,544,547,551,553,555,557,559],{"class":142,"line":250},[140,511,512],{"class":154},"        ?",[140,514,515],{"class":442}," fn",[140,517,446],{"class":154},[140,519,398],{"class":183},[140,521,237],{"class":154},[140,523,524],{"class":150},"query",[140,526,487],{"class":154},[140,528,529],{"class":183}," Builder",[140,531,496],{"class":154},[140,533,237],{"class":154},[140,535,524],{"class":150},[140,537,228],{"class":154},[140,539,540],{"class":189},"where",[140,542,543],{"class":154},"(",[140,545,546],{"class":154},"'",[140,548,550],{"class":549},"sfazB","custom_field_section_id",[140,552,546],{"class":154},[140,554,234],{"class":154},[140,556,237],{"class":154},[140,558,484],{"class":150},[140,560,211],{"class":154},[140,562,564,567],{"class":142,"line":563},7,[140,565,566],{"class":154},"        :",[140,568,507],{"class":154},[140,570,572],{"class":142,"line":571},8,[140,573,574],{"class":154},");\n",[101,576,577],{},"The callback receives:",[579,580,581,588,602],"ul",{},[582,583,584,587],"li",{},[105,585,586],{},"$entityType"," — the entity the field or section belongs to.",[582,589,590,593,594,597,598,601],{},[105,591,592],{},"$type"," — ",[105,595,596],{},"'field'"," or ",[105,599,600],{},"'section'",", so you can scope differently per kind of code.",[582,603,604,607,608,610],{},[105,605,606],{},"$sectionId"," — the section the code is being generated within, or ",[105,609,479],{}," when there\nisn't one (for example, the sectionless field-management table).",[101,612,613,614,616,617,619,620,623,624,627,628,631],{},"Return ",[105,615,479],{}," to leave the uniqueness check global — the default, backward-compatible\nbehavior. Return a closure to narrow it: the closure receives the in-progress ",[105,618,398],{},"\nand must ",[334,621,622],{},"return"," the query to apply. ",[105,625,626],{},"where()","-style mutation also works (it returns\nthe same instance), but a closure that hands back a different instance — e.g.\n",[105,629,630],{},"$query->clone()->where(...)"," — is honored too, since the return value is always what's\nused.",[101,633,634,635,638],{},"Register the callback once, typically in a service provider's ",[105,636,637],{},"boot()"," method.",[640,641,642],"style",{},"html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}",{"title":136,"searchDepth":173,"depth":173,"links":644},[645,648],{"id":98,"depth":173,"text":99,"children":646},[647],{"id":313,"depth":180,"text":314},{"id":360,"depth":173,"text":361},"Scope custom-field resolution to specific sections, and hook into code-uniqueness resolution","md",null,{},{"icon":64},{"title":61,"description":649},"DKT_1V6XFMR_TxUEXJdu2f-IaTD94dcMleGIqFB80nM",[657,659],{"title":56,"path":57,"stem":58,"description":658,"icon":59,"children":-1},"Understanding the Custom Fields database architecture",{"title":71,"path":72,"stem":73,"description":660,"icon":74,"children":-1},"Get help with Custom Fields",1788115963956]