[{"data":1,"prerenderedAt":1653},["ShallowReactive",2],{"navigation":3,"\u002Fdigging-deeper\u002Fseveral-brands":173,"\u002Fdigging-deeper\u002Fseveral-brands-surround":1648},[4,27,69,103,113,135],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":26},"Getting Started","i-heroicons-star","\u002Fgetting-started","1.getting-started",[10,14,18,22],{"title":11,"path":12,"stem":13},"Introduction","\u002Fgetting-started\u002Fintroduction","1.getting-started\u002F1.introduction",{"title":15,"path":16,"stem":17},"Installation","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F2.installation",{"title":19,"path":20,"stem":21},"Quick start","\u002Fgetting-started\u002Fquick-start","1.getting-started\u002F3.quick-start",{"title":23,"path":24,"stem":25},"Upgrade guide","\u002Fgetting-started\u002Fupgrade-guide","1.getting-started\u002F5.upgrade-guide",false,{"title":28,"icon":29,"path":30,"stem":31,"children":32,"page":26},"Essentials","i-heroicons-shield-check","\u002Fessentials","2.essentials",[33,37,41,45,49,53,57,61,65],{"title":34,"path":35,"stem":36},"Controls","\u002Fessentials\u002Fcontrols","2.essentials\u002F1.controls",{"title":38,"path":39,"stem":40},"Perimeters","\u002Fessentials\u002Fperimeters","2.essentials\u002F2.perimeters",{"title":42,"path":43,"stem":44},"Perimeter classes","\u002Fessentials\u002Fperimeter-classes","2.essentials\u002F3.perimeter-classes",{"title":46,"path":47,"stem":48},"Levels","\u002Fessentials\u002Flevels","2.essentials\u002F4.levels",{"title":50,"path":51,"stem":52},"Boundaries","\u002Fessentials\u002Fboundaries","2.essentials\u002F5.boundaries",{"title":54,"path":55,"stem":56},"Parents","\u002Fessentials\u002Fparents","2.essentials\u002F6.parents",{"title":58,"path":59,"stem":60},"Policies","\u002Fessentials\u002Fpolicies","2.essentials\u002F7.policies",{"title":62,"path":63,"stem":64},"Queries","\u002Fessentials\u002Fqueries","2.essentials\u002F8.queries",{"title":66,"path":67,"stem":68},"Readers","\u002Fessentials\u002Freaders","2.essentials\u002F9.readers",{"title":70,"icon":71,"path":72,"stem":73,"children":74,"page":26},"Search","i-heroicons-magnifying-glass","\u002Fsearch","3.search",[75,79,83,87,91,95,99],{"title":76,"path":77,"stem":78},"Search overview","\u002Fsearch\u002Foverview","3.search\u002F1.overview",{"title":80,"path":81,"stem":82},"Engines","\u002Fsearch\u002Fengines","3.search\u002F2.engines",{"title":84,"path":85,"stem":86},"Keeping the keys fresh","\u002Fsearch\u002Fkeeping-the-keys-fresh","3.search\u002F3.keeping-the-keys-fresh",{"title":88,"path":89,"stem":90},"Exceptions and dates","\u002Fsearch\u002Fexceptions-and-dates","3.search\u002F4.exceptions-and-dates",{"title":92,"path":93,"stem":94},"Searching through a parent","\u002Fsearch\u002Fthrough-a-parent","3.search\u002F5.through-a-parent",{"title":96,"path":97,"stem":98},"Search from the browser","\u002Fsearch\u002Ffrom-the-browser","3.search\u002F6.from-the-browser",{"title":100,"path":101,"stem":102},"Your own search client","\u002Fsearch\u002Fyour-own-client","3.search\u002F7.your-own-client",{"title":104,"icon":105,"path":106,"stem":107,"children":108,"page":26},"Integrations","i-heroicons-puzzle-piece","\u002Fintegrations","4.integrations",[109],{"title":110,"path":111,"stem":112},"laravel-rest-api","\u002Fintegrations\u002Flaravel-rest-api","4.integrations\u002F1.laravel-rest-api",{"title":114,"icon":115,"path":116,"stem":117,"children":118,"page":26},"Testing and Tooling","i-heroicons-wrench-screwdriver","\u002Ftesting-and-tooling","5.testing-and-tooling",[119,123,127,131],{"title":120,"path":121,"stem":122},"Testing","\u002Ftesting-and-tooling\u002Ftesting","5.testing-and-tooling\u002F1.testing",{"title":124,"path":125,"stem":126},"access:check","\u002Ftesting-and-tooling\u002Faccess-check","5.testing-and-tooling\u002F2.access-check",{"title":128,"path":129,"stem":130},"Cache and about","\u002Ftesting-and-tooling\u002Fcache-and-about","5.testing-and-tooling\u002F3.cache-and-about",{"title":132,"path":133,"stem":134},"Generators","\u002Ftesting-and-tooling\u002Fgenerators","5.testing-and-tooling\u002F4.generators",{"title":136,"icon":137,"path":138,"stem":139,"children":140,"page":26},"Digging Deeper","i-heroicons-list-bullet","\u002Fdigging-deeper","6.digging-deeper",[141,145,149,153,157,161,165,169],{"title":142,"path":143,"stem":144},"Abilities","\u002Fdigging-deeper\u002Fabilities","6.digging-deeper\u002F1.abilities",{"title":146,"path":147,"stem":148},"Kept decisions","\u002Fdigging-deeper\u002Fdecisions","6.digging-deeper\u002F2.decisions",{"title":150,"path":151,"stem":152},"Batched decisions","\u002Fdigging-deeper\u002Fbatched-decisions","6.digging-deeper\u002F3.batched-decisions",{"title":154,"path":155,"stem":156},"Row checks","\u002Fdigging-deeper\u002Frow-checks","6.digging-deeper\u002F4.row-checks",{"title":158,"path":159,"stem":160},"Several brands","\u002Fdigging-deeper\u002Fseveral-brands","6.digging-deeper\u002F5.several-brands",{"title":162,"path":163,"stem":164},"Row context","\u002Fdigging-deeper\u002Frow-context","6.digging-deeper\u002F6.row-context",{"title":166,"path":167,"stem":168},"What is public in 1.x","\u002Fdigging-deeper\u002Fpublic-api","6.digging-deeper\u002F7.public-api",{"title":170,"path":171,"stem":172},"Use with AI","\u002Fdigging-deeper\u002Fuse-with-ai","6.digging-deeper\u002F8.use-with-ai",{"id":174,"title":158,"body":175,"description":1639,"extension":1640,"links":1641,"meta":1642,"navigation":1643,"path":159,"seo":1644,"sitemap":1645,"stem":160,"updatedAt":1646,"__hash__":1647},"docs\u002F6.digging-deeper\u002F5.several-brands.md",{"type":176,"value":177,"toc":1630},"minimark",[178,188,193,217,220,849,865,900,905,908,911,1247,1260,1264,1271,1565,1578,1582,1591,1598,1606,1610,1626],[179,180,181,182,187],"p",{},"A decision runs under one ",[183,184,186],"a",{"href":185},"\u002Fessentials\u002Freaders#the-decision-context","decision context",": the one the resolver returns when the decision is made. This page covers the lists that span several brands, companies or tenants in one query. Replace \"brand\" with the dimension of your application.",[189,190,192],"h2",{"id":191},"the-brand-is-a-value-of-the-row","The brand is a value of the row",[179,194,195,196,200,201,204,205,208,209,212,213,216],{},"Do not build such a list by switching the decision context between ",[197,198,199],"code",{},"controlledFor()"," calls joined with ",[197,202,203],{},"orWhere()",". Only the list would follow each branch: ",[197,206,207],{},"withAbilities()",", the policy, the kept decisions, ",[197,210,211],{},"Access::preload()"," and the row checks of laravel-rest-api run under the context in force, not under the brand of each row. A post of brand B listed through the rights of brand B would be decided for ",[197,214,215],{},"update"," with the rights of brand A, and kept so.",[179,218,219],{},"When one list spans several brands, the brand is a value of the row, not of the request. Write perimeters that read the brand of the row and filter by the brands where the reader holds the right:",[221,222,228],"pre",{"className":223,"code":224,"filename":225,"language":226,"meta":227,"style":227},"language-php shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","protected function perimeters(): array\n{\n    return [\n        BrandPerimeter::new()\n            ->allowed(fn (User $user, Ability $ability): bool => $user->brandsWhere(\"{$ability} brand posts\") !== [])\n            ->should(fn (User $user, Post $post, Ability $ability): bool => in_array($post->brand_id, $user->brandsWhere(\"{$ability} brand posts\"), true))\n            ->query(function (Builder $query, User $user, Ability $ability): void {\n                $query->whereIn('brand_id', $user->brandsWhere(\"{$ability} brand posts\"));\n            }),\n        OwnPerimeter::new()\n            ->allowed(fn (User $user, Ability $ability): bool => $user->brandsWhere(\"{$ability} own posts\") !== [])\n            ->should(fn (User $user, Post $post, Ability $ability): bool => $post->author_id === $user->id && in_array($post->brand_id, $user->brandsWhere(\"{$ability} own posts\"), true))\n            ->query(function (Builder $query, User $user, Ability $ability): void {\n                $query->whereBelongsTo($user, 'author')->whereIn('brand_id', $user->brandsWhere(\"{$ability} own posts\"));\n            }),\n    ];\n}\n","app\u002FAccess\u002FControls\u002FPostControl.php","php","",[197,229,230,254,260,270,286,370,455,502,549,555,567,627,728,769,832,837,843],{"__ignoreMap":227},[231,232,235,239,242,246,250],"span",{"class":233,"line":234},"line",1,[231,236,238],{"class":237},"spNyl","protected",[231,240,241],{"class":237}," function",[231,243,245],{"class":244},"s2Zo4"," perimeters",[231,247,249],{"class":248},"sMK4o","():",[231,251,253],{"class":252},"sbssI"," array\n",[231,255,257],{"class":233,"line":256},2,[231,258,259],{"class":248},"{\n",[231,261,263,267],{"class":233,"line":262},3,[231,264,266],{"class":265},"s7zQu","    return",[231,268,269],{"class":248}," [\n",[231,271,273,277,280,283],{"class":233,"line":272},4,[231,274,276],{"class":275},"sBMFI","        BrandPerimeter",[231,278,279],{"class":248},"::",[231,281,282],{"class":244},"new",[231,284,285],{"class":248},"()\n",[231,287,289,292,295,298,301,304,307,310,314,317,320,322,325,328,331,334,336,338,341,344,346,349,351,354,358,361,364,367],{"class":233,"line":288},5,[231,290,291],{"class":248},"            ->",[231,293,294],{"class":244},"allowed",[231,296,297],{"class":248},"(",[231,299,300],{"class":237},"fn",[231,302,303],{"class":248}," (",[231,305,306],{"class":275},"User",[231,308,309],{"class":248}," $",[231,311,313],{"class":312},"sTEyZ","user",[231,315,316],{"class":248},",",[231,318,319],{"class":275}," Ability",[231,321,309],{"class":248},[231,323,324],{"class":312},"ability",[231,326,327],{"class":248},"):",[231,329,330],{"class":252}," bool",[231,332,333],{"class":248}," =>",[231,335,309],{"class":248},[231,337,313],{"class":312},[231,339,340],{"class":248},"->",[231,342,343],{"class":244},"brandsWhere",[231,345,297],{"class":248},[231,347,348],{"class":248},"\"{$",[231,350,324],{"class":312},[231,352,353],{"class":248},"}",[231,355,357],{"class":356},"sfazB"," brand posts",[231,359,360],{"class":248},"\"",[231,362,363],{"class":248},")",[231,365,366],{"class":248}," !==",[231,368,369],{"class":248}," [])\n",[231,371,373,375,378,380,382,384,386,388,390,392,395,397,400,402,404,406,408,410,412,414,417,420,422,424,427,429,431,433,435,437,439,441,443,445,447,449,452],{"class":233,"line":372},6,[231,374,291],{"class":248},[231,376,377],{"class":244},"should",[231,379,297],{"class":248},[231,381,300],{"class":237},[231,383,303],{"class":248},[231,385,306],{"class":275},[231,387,309],{"class":248},[231,389,313],{"class":312},[231,391,316],{"class":248},[231,393,394],{"class":275}," Post",[231,396,309],{"class":248},[231,398,399],{"class":312},"post",[231,401,316],{"class":248},[231,403,319],{"class":275},[231,405,309],{"class":248},[231,407,324],{"class":312},[231,409,327],{"class":248},[231,411,330],{"class":252},[231,413,333],{"class":248},[231,415,416],{"class":244}," in_array",[231,418,419],{"class":248},"($",[231,421,399],{"class":312},[231,423,340],{"class":248},[231,425,426],{"class":312},"brand_id",[231,428,316],{"class":248},[231,430,309],{"class":248},[231,432,313],{"class":312},[231,434,340],{"class":248},[231,436,343],{"class":244},[231,438,297],{"class":248},[231,440,348],{"class":248},[231,442,324],{"class":312},[231,444,353],{"class":248},[231,446,357],{"class":356},[231,448,360],{"class":248},[231,450,451],{"class":248},"),",[231,453,454],{"class":248}," true))\n",[231,456,458,460,463,465,468,470,473,475,477,479,482,484,486,488,490,492,494,496,499],{"class":233,"line":457},7,[231,459,291],{"class":248},[231,461,462],{"class":244},"query",[231,464,297],{"class":248},[231,466,467],{"class":237},"function",[231,469,303],{"class":248},[231,471,472],{"class":275},"Builder",[231,474,309],{"class":248},[231,476,462],{"class":312},[231,478,316],{"class":248},[231,480,481],{"class":275}," User",[231,483,309],{"class":248},[231,485,313],{"class":312},[231,487,316],{"class":248},[231,489,319],{"class":275},[231,491,309],{"class":248},[231,493,324],{"class":312},[231,495,327],{"class":248},[231,497,498],{"class":252}," void",[231,500,501],{"class":248}," {\n",[231,503,505,508,510,512,515,517,520,522,524,526,528,530,532,534,536,538,540,542,544,546],{"class":233,"line":504},8,[231,506,507],{"class":248},"                $",[231,509,462],{"class":312},[231,511,340],{"class":248},[231,513,514],{"class":244},"whereIn",[231,516,297],{"class":248},[231,518,519],{"class":248},"'",[231,521,426],{"class":356},[231,523,519],{"class":248},[231,525,316],{"class":248},[231,527,309],{"class":248},[231,529,313],{"class":312},[231,531,340],{"class":248},[231,533,343],{"class":244},[231,535,297],{"class":248},[231,537,348],{"class":248},[231,539,324],{"class":312},[231,541,353],{"class":248},[231,543,357],{"class":356},[231,545,360],{"class":248},[231,547,548],{"class":248},"));\n",[231,550,552],{"class":233,"line":551},9,[231,553,554],{"class":248},"            }),\n",[231,556,558,561,563,565],{"class":233,"line":557},10,[231,559,560],{"class":275},"        OwnPerimeter",[231,562,279],{"class":248},[231,564,282],{"class":244},[231,566,285],{"class":248},[231,568,570,572,574,576,578,580,582,584,586,588,590,592,594,596,598,600,602,604,606,608,610,612,614,616,619,621,623,625],{"class":233,"line":569},11,[231,571,291],{"class":248},[231,573,294],{"class":244},[231,575,297],{"class":248},[231,577,300],{"class":237},[231,579,303],{"class":248},[231,581,306],{"class":275},[231,583,309],{"class":248},[231,585,313],{"class":312},[231,587,316],{"class":248},[231,589,319],{"class":275},[231,591,309],{"class":248},[231,593,324],{"class":312},[231,595,327],{"class":248},[231,597,330],{"class":252},[231,599,333],{"class":248},[231,601,309],{"class":248},[231,603,313],{"class":312},[231,605,340],{"class":248},[231,607,343],{"class":244},[231,609,297],{"class":248},[231,611,348],{"class":248},[231,613,324],{"class":312},[231,615,353],{"class":248},[231,617,618],{"class":356}," own posts",[231,620,360],{"class":248},[231,622,363],{"class":248},[231,624,366],{"class":248},[231,626,369],{"class":248},[231,628,630,632,634,636,638,640,642,644,646,648,650,652,654,656,658,660,662,664,666,668,670,672,674,677,680,682,684,686,689,692,694,696,698,700,702,704,706,708,710,712,714,716,718,720,722,724,726],{"class":233,"line":629},12,[231,631,291],{"class":248},[231,633,377],{"class":244},[231,635,297],{"class":248},[231,637,300],{"class":237},[231,639,303],{"class":248},[231,641,306],{"class":275},[231,643,309],{"class":248},[231,645,313],{"class":312},[231,647,316],{"class":248},[231,649,394],{"class":275},[231,651,309],{"class":248},[231,653,399],{"class":312},[231,655,316],{"class":248},[231,657,319],{"class":275},[231,659,309],{"class":248},[231,661,324],{"class":312},[231,663,327],{"class":248},[231,665,330],{"class":252},[231,667,333],{"class":248},[231,669,309],{"class":248},[231,671,399],{"class":312},[231,673,340],{"class":248},[231,675,676],{"class":312},"author_id ",[231,678,679],{"class":248},"===",[231,681,309],{"class":248},[231,683,313],{"class":312},[231,685,340],{"class":248},[231,687,688],{"class":312},"id ",[231,690,691],{"class":248},"&&",[231,693,416],{"class":244},[231,695,419],{"class":248},[231,697,399],{"class":312},[231,699,340],{"class":248},[231,701,426],{"class":312},[231,703,316],{"class":248},[231,705,309],{"class":248},[231,707,313],{"class":312},[231,709,340],{"class":248},[231,711,343],{"class":244},[231,713,297],{"class":248},[231,715,348],{"class":248},[231,717,324],{"class":312},[231,719,353],{"class":248},[231,721,618],{"class":356},[231,723,360],{"class":248},[231,725,451],{"class":248},[231,727,454],{"class":248},[231,729,731,733,735,737,739,741,743,745,747,749,751,753,755,757,759,761,763,765,767],{"class":233,"line":730},13,[231,732,291],{"class":248},[231,734,462],{"class":244},[231,736,297],{"class":248},[231,738,467],{"class":237},[231,740,303],{"class":248},[231,742,472],{"class":275},[231,744,309],{"class":248},[231,746,462],{"class":312},[231,748,316],{"class":248},[231,750,481],{"class":275},[231,752,309],{"class":248},[231,754,313],{"class":312},[231,756,316],{"class":248},[231,758,319],{"class":275},[231,760,309],{"class":248},[231,762,324],{"class":312},[231,764,327],{"class":248},[231,766,498],{"class":252},[231,768,501],{"class":248},[231,770,772,774,776,778,781,783,785,787,790,793,795,798,800,802,804,806,808,810,812,814,816,818,820,822,824,826,828,830],{"class":233,"line":771},14,[231,773,507],{"class":248},[231,775,462],{"class":312},[231,777,340],{"class":248},[231,779,780],{"class":244},"whereBelongsTo",[231,782,419],{"class":248},[231,784,313],{"class":312},[231,786,316],{"class":248},[231,788,789],{"class":248}," '",[231,791,792],{"class":356},"author",[231,794,519],{"class":248},[231,796,797],{"class":248},")->",[231,799,514],{"class":244},[231,801,297],{"class":248},[231,803,519],{"class":248},[231,805,426],{"class":356},[231,807,519],{"class":248},[231,809,316],{"class":248},[231,811,309],{"class":248},[231,813,313],{"class":312},[231,815,340],{"class":248},[231,817,343],{"class":244},[231,819,297],{"class":248},[231,821,348],{"class":248},[231,823,324],{"class":312},[231,825,353],{"class":248},[231,827,618],{"class":356},[231,829,360],{"class":248},[231,831,548],{"class":248},[231,833,835],{"class":233,"line":834},15,[231,836,554],{"class":248},[231,838,840],{"class":233,"line":839},16,[231,841,842],{"class":248},"    ];\n",[231,844,846],{"class":233,"line":845},17,[231,847,848],{"class":248},"}\n",[179,850,851,854,855,858,859,861,862,864],{},[197,852,853],{},"brandsWhere()"," stands for a method of your application that returns the brands where the user holds a permission. ",[197,856,857],{},"Post::controlled()"," then lists the posts of every brand of the reader in one query, and the policy, ",[197,860,207],{}," and ",[197,863,211],{}," decide each row from its own brand, whatever the current one.",[866,867,868,880,890],"ul",{},[869,870,871,879],"li",{},[872,873,874,875,878],"strong",{},"Keep these perimeters out of ",[197,876,877],{},"Levels::of()","."," A group applies only the highest level the reader reaches, in any brand: a reader who sees every post of brand A and only their own posts of brand B would lose their posts of brand B. Loose perimeters add up, each filtered by its own brands.",[869,881,882,885,886,889],{},[872,883,884],{},"Keep the brand out of the boundary."," ",[197,887,888],{},"Boundary::where()"," holds one value per reader, so a boundary that reads the current brand cuts the list to that brand. Keep in the boundary what is the same for every row the reader may reach, such as the tenant.",[869,891,892,893,899],{},"Check the result with ",[183,894,896],{"href":895},"\u002Ftesting-and-tooling\u002Ftesting#the-decisions",[197,897,898],{},"assertControlAgrees()"," on posts of several brands.",[901,902,904],"h3",{"id":903},"one-level-per-brand","One level per brand",[179,906,907],{},"The loose perimeters already give each brand its own level: in each brand, their union is the highest level the reader reaches there. Never wrap a group, or its levels, in a perimeter that picks the level brand by brand: the package reads only what each perimeter of the list declares.",[179,909,910],{},"To keep what a group saves, the lower levels left out of the SQL, filter each lower level by the brands where no higher level applies:",[221,912,914],{"className":223,"code":913,"language":226,"meta":227,"style":227},"OwnPerimeter::new()\n    ->allowed(fn (User $user, Ability $ability): bool => $user->brandsOnlyWhere(\"{$ability} own posts\", above: [\"{$ability} brand posts\"]) !== [])\n    ->should(fn (User $user, Post $post, Ability $ability): bool => $post->author_id === $user->id && in_array($post->brand_id, $user->brandsOnlyWhere(\"{$ability} own posts\", above: [\"{$ability} brand posts\"]), true))\n    ->query(function (Builder $query, User $user, Ability $ability): void {\n        $query->whereBelongsTo($user, 'author')->whereIn('brand_id', $user->brandsOnlyWhere(\"{$ability} own posts\", above: [\"{$ability} brand posts\"]));\n    }),\n",[197,915,916,927,1009,1124,1164,1242],{"__ignoreMap":227},[231,917,918,921,923,925],{"class":233,"line":234},[231,919,920],{"class":275},"OwnPerimeter",[231,922,279],{"class":248},[231,924,282],{"class":244},[231,926,285],{"class":248},[231,928,929,932,934,936,938,940,942,944,946,948,950,952,954,956,958,960,962,964,966,969,971,973,975,977,979,981,983,986,989,992,994,996,998,1000,1002,1005,1007],{"class":233,"line":256},[231,930,931],{"class":248},"    ->",[231,933,294],{"class":244},[231,935,297],{"class":248},[231,937,300],{"class":237},[231,939,303],{"class":248},[231,941,306],{"class":275},[231,943,309],{"class":248},[231,945,313],{"class":312},[231,947,316],{"class":248},[231,949,319],{"class":275},[231,951,309],{"class":248},[231,953,324],{"class":312},[231,955,327],{"class":248},[231,957,330],{"class":252},[231,959,333],{"class":248},[231,961,309],{"class":248},[231,963,313],{"class":312},[231,965,340],{"class":248},[231,967,968],{"class":244},"brandsOnlyWhere",[231,970,297],{"class":248},[231,972,348],{"class":248},[231,974,324],{"class":312},[231,976,353],{"class":248},[231,978,618],{"class":356},[231,980,360],{"class":248},[231,982,316],{"class":248},[231,984,985],{"class":275}," above",[231,987,988],{"class":248},":",[231,990,991],{"class":248}," [",[231,993,348],{"class":248},[231,995,324],{"class":312},[231,997,353],{"class":248},[231,999,357],{"class":356},[231,1001,360],{"class":248},[231,1003,1004],{"class":248},"])",[231,1006,366],{"class":248},[231,1008,369],{"class":248},[231,1010,1011,1013,1015,1017,1019,1021,1023,1025,1027,1029,1031,1033,1035,1037,1039,1041,1043,1045,1047,1049,1051,1053,1055,1057,1059,1061,1063,1065,1067,1069,1071,1073,1075,1077,1079,1081,1083,1085,1087,1089,1091,1093,1095,1097,1099,1101,1103,1105,1107,1109,1111,1113,1115,1117,1119,1122],{"class":233,"line":262},[231,1012,931],{"class":248},[231,1014,377],{"class":244},[231,1016,297],{"class":248},[231,1018,300],{"class":237},[231,1020,303],{"class":248},[231,1022,306],{"class":275},[231,1024,309],{"class":248},[231,1026,313],{"class":312},[231,1028,316],{"class":248},[231,1030,394],{"class":275},[231,1032,309],{"class":248},[231,1034,399],{"class":312},[231,1036,316],{"class":248},[231,1038,319],{"class":275},[231,1040,309],{"class":248},[231,1042,324],{"class":312},[231,1044,327],{"class":248},[231,1046,330],{"class":252},[231,1048,333],{"class":248},[231,1050,309],{"class":248},[231,1052,399],{"class":312},[231,1054,340],{"class":248},[231,1056,676],{"class":312},[231,1058,679],{"class":248},[231,1060,309],{"class":248},[231,1062,313],{"class":312},[231,1064,340],{"class":248},[231,1066,688],{"class":312},[231,1068,691],{"class":248},[231,1070,416],{"class":244},[231,1072,419],{"class":248},[231,1074,399],{"class":312},[231,1076,340],{"class":248},[231,1078,426],{"class":312},[231,1080,316],{"class":248},[231,1082,309],{"class":248},[231,1084,313],{"class":312},[231,1086,340],{"class":248},[231,1088,968],{"class":244},[231,1090,297],{"class":248},[231,1092,348],{"class":248},[231,1094,324],{"class":312},[231,1096,353],{"class":248},[231,1098,618],{"class":356},[231,1100,360],{"class":248},[231,1102,316],{"class":248},[231,1104,985],{"class":275},[231,1106,988],{"class":248},[231,1108,991],{"class":248},[231,1110,348],{"class":248},[231,1112,324],{"class":312},[231,1114,353],{"class":248},[231,1116,357],{"class":356},[231,1118,360],{"class":248},[231,1120,1121],{"class":248},"]),",[231,1123,454],{"class":248},[231,1125,1126,1128,1130,1132,1134,1136,1138,1140,1142,1144,1146,1148,1150,1152,1154,1156,1158,1160,1162],{"class":233,"line":272},[231,1127,931],{"class":248},[231,1129,462],{"class":244},[231,1131,297],{"class":248},[231,1133,467],{"class":237},[231,1135,303],{"class":248},[231,1137,472],{"class":275},[231,1139,309],{"class":248},[231,1141,462],{"class":312},[231,1143,316],{"class":248},[231,1145,481],{"class":275},[231,1147,309],{"class":248},[231,1149,313],{"class":312},[231,1151,316],{"class":248},[231,1153,319],{"class":275},[231,1155,309],{"class":248},[231,1157,324],{"class":312},[231,1159,327],{"class":248},[231,1161,498],{"class":252},[231,1163,501],{"class":248},[231,1165,1166,1169,1171,1173,1175,1177,1179,1181,1183,1185,1187,1189,1191,1193,1195,1197,1199,1201,1203,1205,1207,1209,1211,1213,1215,1217,1219,1221,1223,1225,1227,1229,1231,1233,1235,1237,1239],{"class":233,"line":288},[231,1167,1168],{"class":248},"        $",[231,1170,462],{"class":312},[231,1172,340],{"class":248},[231,1174,780],{"class":244},[231,1176,419],{"class":248},[231,1178,313],{"class":312},[231,1180,316],{"class":248},[231,1182,789],{"class":248},[231,1184,792],{"class":356},[231,1186,519],{"class":248},[231,1188,797],{"class":248},[231,1190,514],{"class":244},[231,1192,297],{"class":248},[231,1194,519],{"class":248},[231,1196,426],{"class":356},[231,1198,519],{"class":248},[231,1200,316],{"class":248},[231,1202,309],{"class":248},[231,1204,313],{"class":312},[231,1206,340],{"class":248},[231,1208,968],{"class":244},[231,1210,297],{"class":248},[231,1212,348],{"class":248},[231,1214,324],{"class":312},[231,1216,353],{"class":248},[231,1218,618],{"class":356},[231,1220,360],{"class":248},[231,1222,316],{"class":248},[231,1224,985],{"class":275},[231,1226,988],{"class":248},[231,1228,991],{"class":248},[231,1230,348],{"class":248},[231,1232,324],{"class":312},[231,1234,353],{"class":248},[231,1236,357],{"class":356},[231,1238,360],{"class":248},[231,1240,1241],{"class":248},"]));\n",[231,1243,1244],{"class":233,"line":372},[231,1245,1246],{"class":248},"    }),\n",[179,1248,1249,1252,1253,1255,1256,1259],{},[197,1250,1251],{},"brandsOnlyWhere()"," stands for ",[197,1254,853],{}," of the first permission minus the brands of every higher level, whose permissions ",[197,1257,1258],{},"above"," lists, so each brand is read by one level only.",[901,1261,1263],{"id":1262},"search-keys","Search keys",[179,1265,1266,1267,1270],{},"On a searchable model, key these perimeters by the brand of the row and the brands where the reader holds the ",[197,1268,1269],{},"view"," right:",[221,1272,1274],{"className":223,"code":1273,"language":226,"meta":227,"style":227},"BrandPerimeter::new()\n    \u002F\u002F allowed(), should() and query() as above\n    ->searchKeys(\n        name: 'brand',\n        row: fn (Post $post) => $post->brand_id,\n        reader: fn (User $user) => $user->brandsWhere('view brand posts'),\n    ),\nOwnPerimeter::new()\n    \u002F\u002F allowed(), should() and query() as above\n    ->searchKeys(\n        name: 'own',\n        row: fn (Post $post) => [[$post->brand_id, $post->author_id]],\n        reader: fn (User $user) => array_map(fn (int $brand): array => [$brand, $user->id], $user->brandsWhere('view own posts')),\n    ),\n",[197,1275,1276,1287,1293,1303,1320,1353,1394,1399,1409,1413,1421,1436,1479,1561],{"__ignoreMap":227},[231,1277,1278,1281,1283,1285],{"class":233,"line":234},[231,1279,1280],{"class":275},"BrandPerimeter",[231,1282,279],{"class":248},[231,1284,282],{"class":244},[231,1286,285],{"class":248},[231,1288,1289],{"class":233,"line":256},[231,1290,1292],{"class":1291},"sHwdD","    \u002F\u002F allowed(), should() and query() as above\n",[231,1294,1295,1297,1300],{"class":233,"line":262},[231,1296,931],{"class":248},[231,1298,1299],{"class":244},"searchKeys",[231,1301,1302],{"class":248},"(\n",[231,1304,1305,1308,1310,1312,1315,1317],{"class":233,"line":272},[231,1306,1307],{"class":275},"        name",[231,1309,988],{"class":248},[231,1311,789],{"class":248},[231,1313,1314],{"class":356},"brand",[231,1316,519],{"class":248},[231,1318,1319],{"class":248},",\n",[231,1321,1322,1325,1327,1330,1332,1335,1337,1339,1341,1343,1345,1347,1349,1351],{"class":233,"line":288},[231,1323,1324],{"class":275},"        row",[231,1326,988],{"class":248},[231,1328,1329],{"class":237}," fn",[231,1331,303],{"class":248},[231,1333,1334],{"class":275},"Post",[231,1336,309],{"class":248},[231,1338,399],{"class":312},[231,1340,363],{"class":248},[231,1342,333],{"class":248},[231,1344,309],{"class":248},[231,1346,399],{"class":312},[231,1348,340],{"class":248},[231,1350,426],{"class":312},[231,1352,1319],{"class":248},[231,1354,1355,1358,1360,1362,1364,1366,1368,1370,1372,1374,1376,1378,1380,1382,1384,1386,1389,1391],{"class":233,"line":372},[231,1356,1357],{"class":275},"        reader",[231,1359,988],{"class":248},[231,1361,1329],{"class":237},[231,1363,303],{"class":248},[231,1365,306],{"class":275},[231,1367,309],{"class":248},[231,1369,313],{"class":312},[231,1371,363],{"class":248},[231,1373,333],{"class":248},[231,1375,309],{"class":248},[231,1377,313],{"class":312},[231,1379,340],{"class":248},[231,1381,343],{"class":244},[231,1383,297],{"class":248},[231,1385,519],{"class":248},[231,1387,1388],{"class":356},"view brand posts",[231,1390,519],{"class":248},[231,1392,1393],{"class":248},"),\n",[231,1395,1396],{"class":233,"line":457},[231,1397,1398],{"class":248},"    ),\n",[231,1400,1401,1403,1405,1407],{"class":233,"line":504},[231,1402,920],{"class":275},[231,1404,279],{"class":248},[231,1406,282],{"class":244},[231,1408,285],{"class":248},[231,1410,1411],{"class":233,"line":551},[231,1412,1292],{"class":1291},[231,1414,1415,1417,1419],{"class":233,"line":557},[231,1416,931],{"class":248},[231,1418,1299],{"class":244},[231,1420,1302],{"class":248},[231,1422,1423,1425,1427,1429,1432,1434],{"class":233,"line":569},[231,1424,1307],{"class":275},[231,1426,988],{"class":248},[231,1428,789],{"class":248},[231,1430,1431],{"class":356},"own",[231,1433,519],{"class":248},[231,1435,1319],{"class":248},[231,1437,1438,1440,1442,1444,1446,1448,1450,1452,1454,1456,1459,1461,1463,1465,1467,1469,1471,1473,1476],{"class":233,"line":629},[231,1439,1324],{"class":275},[231,1441,988],{"class":248},[231,1443,1329],{"class":237},[231,1445,303],{"class":248},[231,1447,1334],{"class":275},[231,1449,309],{"class":248},[231,1451,399],{"class":312},[231,1453,363],{"class":248},[231,1455,333],{"class":248},[231,1457,1458],{"class":248}," [[$",[231,1460,399],{"class":312},[231,1462,340],{"class":248},[231,1464,426],{"class":312},[231,1466,316],{"class":248},[231,1468,309],{"class":248},[231,1470,399],{"class":312},[231,1472,340],{"class":248},[231,1474,1475],{"class":312},"author_id",[231,1477,1478],{"class":248},"]],\n",[231,1480,1481,1483,1485,1487,1489,1491,1493,1495,1497,1499,1502,1504,1506,1508,1511,1513,1515,1517,1520,1522,1525,1527,1529,1531,1533,1535,1538,1541,1543,1545,1547,1549,1551,1553,1556,1558],{"class":233,"line":730},[231,1482,1357],{"class":275},[231,1484,988],{"class":248},[231,1486,1329],{"class":237},[231,1488,303],{"class":248},[231,1490,306],{"class":275},[231,1492,309],{"class":248},[231,1494,313],{"class":312},[231,1496,363],{"class":248},[231,1498,333],{"class":248},[231,1500,1501],{"class":244}," array_map",[231,1503,297],{"class":248},[231,1505,300],{"class":237},[231,1507,303],{"class":248},[231,1509,1510],{"class":252},"int",[231,1512,309],{"class":248},[231,1514,1314],{"class":312},[231,1516,327],{"class":248},[231,1518,1519],{"class":252}," array",[231,1521,333],{"class":248},[231,1523,1524],{"class":248}," [$",[231,1526,1314],{"class":312},[231,1528,316],{"class":248},[231,1530,309],{"class":248},[231,1532,313],{"class":312},[231,1534,340],{"class":248},[231,1536,1537],{"class":312},"id",[231,1539,1540],{"class":248},"],",[231,1542,309],{"class":248},[231,1544,313],{"class":312},[231,1546,340],{"class":248},[231,1548,343],{"class":244},[231,1550,297],{"class":248},[231,1552,519],{"class":248},[231,1554,1555],{"class":356},"view own posts",[231,1557,519],{"class":248},[231,1559,1560],{"class":248},")),\n",[231,1562,1563],{"class":233,"line":771},[231,1564,1398],{"class":248},[179,1566,1567,1568,1571,1572,899],{},"The key of an own post holds its brand with its author: an author key alone would find the reader's posts in every brand, even one where they hold no right. ",[197,1569,1570],{},"Post::search()->controlled()"," finds the posts of every brand of the reader, and laravel-rest-api serves the lists and the searches of several brands under one decision context, with its extension as it is. Check with ",[183,1573,1575],{"href":1574},"\u002Ftesting-and-tooling\u002Ftesting#the-search",[197,1576,1577],{},"assertSearchAgrees()",[189,1579,1581],{"id":1580},"a-child-read-through-its-parent","A child read through its parent",[179,1583,1584,1585,1590],{},"A ",[183,1586,1587],{"href":55},[197,1588,1589],{},"ThroughParent"," decides its parent under the decision context of the request, and never reads the brand of the child row. With the perimeters above, which read the brand of the row and never the current brand, that changes nothing: a comment is readable wherever its post is. A condition on the comment's own brand and the reader's rights goes in the comment's boundary.",[179,1592,1593,1594,1597],{},"It is different when the control of the parent reads the brands from the decision context, such as ",[197,1595,1596],{},"['brands' => '1,2']"," for a headquarters that reads two brands. The parent is then decided under the whole context, and being readable in any one of its brands is enough. Take a post P readable only in brand B, and a comment of brand A on P under a comment boundary that keeps the brands of the request: under A and B, the comment is listed and granted, since P is readable in B, though neither brand alone grants it. Every path agrees on this wide answer, so the assertions cannot catch it.",[179,1599,1600,1603,1604,878],{},[197,1601,1602],{},"decidedInRowContext()"," decides the parent, for each child row, within the brand that the row holds: see ",[183,1605,162],{"href":163},[901,1607,1609],{"id":1608},"without-the-row-context","Without the row context",[179,1611,1612,1613,1615,1616,1618,1619,1622,1623,1625],{},"Without ",[197,1614,1602],{},", serve the children of such a parent one brand at a time, with a boundary on the child that keeps its rows to the brand of the request. To show several brands on one page, run one query per brand, switch the decision context between them, and decide everything the page needs on those rows, ",[197,1617,207],{},", every ",[197,1620,1621],{},"can()"," and the API resources that check them, while the context of their brand is in force. Never join those queries with ",[197,1624,203],{},". laravel-rest-api decides under the context of the request, so there one brand at a time means one brand per request.",[1627,1628,1629],"style",{},"html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}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 .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}",{"title":227,"searchDepth":234,"depth":256,"links":1631},[1632,1636],{"id":191,"depth":256,"text":192,"children":1633},[1634,1635],{"id":903,"depth":262,"text":904},{"id":1262,"depth":262,"text":1263},{"id":1580,"depth":256,"text":1581,"children":1637},[1638],{"id":1608,"depth":262,"text":1609},"List the rows of several brands, tenants or companies in one query with perimeters that read the brand of the row, and know when a parent needs the row's brand.","md",null,{},true,{"title":158,"description":1639},{"loc":159,"lastmod":1646},"2026-11-21T16:10:34+01:00","v50Ej9LsGOiMQ-OOyStJXJTbIx8E-Qq3InivZgFnRrY",[1649,1651],{"title":154,"path":155,"stem":156,"description":1650,"children":-1},"How the policy checks one row, in memory or in one SQL query, and how a control or a perimeter tells which perimeters apply and which one grants a row.",{"title":162,"path":163,"stem":164,"description":1652,"children":-1},"Decide the parent of a ThroughParent in the brand or tenant of each child row with decidedInRowContext() and Access::rowContextUsing(), and test the switch.",1795277182292]