[{"data":1,"prerenderedAt":1425},["ShallowReactive",2],{"navigation":3,"\u002Fessentials\u002Fqueries":173,"\u002Fessentials\u002Fqueries-surround":1420},[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":62,"body":175,"description":1412,"extension":1413,"links":1414,"meta":1415,"navigation":371,"path":63,"seo":1416,"sitemap":1417,"stem":64,"updatedAt":1418,"__hash__":1419},"docs\u002F2.essentials\u002F8.queries.md",{"type":176,"value":177,"toc":1400},"minimark",[178,183,192,279,293,307,312,325,329,340,460,477,518,528,532,538,687,696,700,709,765,781,859,862,932,936,947,1141,1144,1212,1216,1226,1230,1248,1313,1343,1366,1370,1396],[179,180,182],"h2",{"id":181},"controlled-queries","Controlled queries",[184,185,186,187,191],"p",{},"The ",[188,189,190],"code",{},"HasControl"," trait adds three local scopes to the model:",[193,194,199],"pre",{"className":195,"code":196,"language":197,"meta":198,"style":198},"language-php shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","Post::controlled()->paginate();          \u002F\u002F the posts the signed-in user may view\nPost::controlledFor($user)->get();       \u002F\u002F the posts a named reader may view\nPost::uncontrolled()->count();           \u002F\u002F every post, on purpose\n","php","",[188,200,201,231,259],{"__ignoreMap":198},[202,203,206,210,214,218,221,224,227],"span",{"class":204,"line":205},"line",1,[202,207,209],{"class":208},"sBMFI","Post",[202,211,213],{"class":212},"sMK4o","::",[202,215,217],{"class":216},"s2Zo4","controlled",[202,219,220],{"class":212},"()->",[202,222,223],{"class":216},"paginate",[202,225,226],{"class":212},"();",[202,228,230],{"class":229},"sHwdD","          \u002F\u002F the posts the signed-in user may view\n",[202,232,234,236,238,241,244,248,251,254,256],{"class":204,"line":233},2,[202,235,209],{"class":208},[202,237,213],{"class":212},[202,239,240],{"class":216},"controlledFor",[202,242,243],{"class":212},"($",[202,245,247],{"class":246},"sTEyZ","user",[202,249,250],{"class":212},")->",[202,252,253],{"class":216},"get",[202,255,226],{"class":212},[202,257,258],{"class":229},"       \u002F\u002F the posts a named reader may view\n",[202,260,262,264,266,269,271,274,276],{"class":204,"line":261},3,[202,263,209],{"class":208},[202,265,213],{"class":212},[202,267,268],{"class":216},"uncontrolled",[202,270,220],{"class":212},[202,272,273],{"class":216},"count",[202,275,226],{"class":212},[202,277,278],{"class":229},"           \u002F\u002F every post, on purpose\n",[184,280,281,284,285,288,289,292],{},[188,282,283],{},"controlled()"," reads the signed-in user, with ",[188,286,287],{},"Auth::user()",", when the query is built. The control adds the constraints of the perimeters that the user reaches, and of the boundary, in SQL, in one nested ",[188,290,291],{},"where",".",[184,294,295,299,300,303,304,306],{},[296,297,298],"strong",{},"A query is controlled only when it says so."," ",[188,301,302],{},"Post::query()->get()"," reads every row: the trait registers no global scope. Add ",[188,305,283],{}," to every query that must be filtered.",[308,309,311],"h3",{"id":310},"guests-see-nothing","Guests see nothing",[184,313,314,315,317,318,321,322,292],{},"Without a signed-in user, ",[188,316,283],{}," reads no row, whatever the ability. So does ",[188,319,320],{},"controlledFor(null)",": a missing reader never means every row. A user that no perimeter allows reads no row either: the query gets ",[188,323,324],{},"0=1",[179,326,328],{"id":327},"listing-another-ability","Listing another ability",[184,330,331,332,335,336,339],{},"Both scopes list the ",[188,333,334],{},"view"," rows by default. Pass another ability, as a name or an ",[188,337,338],{},"Ability",", to list the rows the reader may act on:",[193,341,343],{"className":195,"code":342,"language":197,"meta":198,"style":198},"use Lomkit\\Access\\Ability;\n\nPost::controlled('update')->paginate();\nPost::controlledFor($user, Ability::delete())->count();\nPost::controlledFor($user, 'approve')->get();\n",[188,344,345,367,373,400,431],{"__ignoreMap":198},[202,346,347,351,354,357,360,362,364],{"class":204,"line":205},[202,348,350],{"class":349},"sbssI","use",[202,352,353],{"class":246}," Lomkit",[202,355,356],{"class":212},"\\",[202,358,359],{"class":246},"Access",[202,361,356],{"class":212},[202,363,338],{"class":246},[202,365,366],{"class":212},";\n",[202,368,369],{"class":204,"line":233},[202,370,372],{"emptyLinePlaceholder":371},true,"\n",[202,374,375,377,379,381,384,387,391,393,395,397],{"class":204,"line":261},[202,376,209],{"class":208},[202,378,213],{"class":212},[202,380,217],{"class":216},[202,382,383],{"class":212},"(",[202,385,386],{"class":212},"'",[202,388,390],{"class":389},"sfazB","update",[202,392,386],{"class":212},[202,394,250],{"class":212},[202,396,223],{"class":216},[202,398,399],{"class":212},"();\n",[202,401,403,405,407,409,411,413,416,419,421,424,427,429],{"class":204,"line":402},4,[202,404,209],{"class":208},[202,406,213],{"class":212},[202,408,240],{"class":216},[202,410,243],{"class":212},[202,412,247],{"class":246},[202,414,415],{"class":212},",",[202,417,418],{"class":208}," Ability",[202,420,213],{"class":212},[202,422,423],{"class":216},"delete",[202,425,426],{"class":212},"())->",[202,428,273],{"class":216},[202,430,399],{"class":212},[202,432,434,436,438,440,442,444,446,449,452,454,456,458],{"class":204,"line":433},5,[202,435,209],{"class":208},[202,437,213],{"class":212},[202,439,240],{"class":216},[202,441,243],{"class":212},[202,443,247],{"class":246},[202,445,415],{"class":212},[202,447,448],{"class":212}," '",[202,450,451],{"class":389},"approve",[202,453,386],{"class":212},[202,455,250],{"class":212},[202,457,253],{"class":216},[202,459,399],{"class":212},[184,461,462,463,470,471,473,474,476],{},"The list follows the policy for that ability: the perimeters that allow the reader for it, the level reached for it in each group, the boundary checked for it, and the abilities a parent delegates. A post archived under ",[464,465,467],"a",{"href":466},"\u002Fessentials\u002Fboundaries#read-only-rows",[188,468,469],{},"readOnlyWhenNotNull('archived_at')"," stays in the ",[188,472,334],{}," list and leaves the ",[188,475,390],{}," list.",[478,479,480,498,508],"ul",{},[481,482,483,484,487,488,491,492,494,495,497],"li",{},"A name goes through ",[188,485,486],{},"abilityFor()",": ",[188,489,490],{},"viewAny"," lists ",[188,493,334],{},", and a business ability such as ",[188,496,451],{}," lists its rows.",[481,499,500,503,504,507],{},[188,501,502],{},"create"," throws ",[188,505,506],{},"UnlistableAbilityException",", since the policy judges it on a draft only.",[481,509,510,511,514,515,292],{},"One ability per scope: a second argument, such as ",[188,512,513],{},"controlled('view', 'update')",", throws ",[188,516,517],{},"IgnoredArgumentException",[184,519,520,521,524,525,292],{},"The list is what the control grants. A rule that an overridden policy method adds, or a ",[188,522,523],{},"Gate::before()",", does not change it: keep the rules in the control, see ",[464,526,58],{"href":527},"\u002Fessentials\u002Fpolicies#keep-the-rules-in-the-control",[179,529,531],{"id":530},"named-readers","Named readers",[184,533,534,537],{},[188,535,536],{},"controlledFor($reader)"," applies the control for a reader you name. Use it where no user is signed in, such as jobs, listeners and commands, or to act for another user:",[193,539,541],{"className":195,"code":540,"language":197,"meta":198,"style":198},"class SendDigest implements ShouldQueue\n{\n    public function __construct(public User $recipient) {}\n\n    public function handle(): void\n    {\n        $posts = Post::controlledFor($this->recipient)->latest()->limit(10)->get();\n\n        \u002F\u002F ...\n    }\n}\n",[188,542,543,558,563,594,598,613,619,664,669,675,681],{"__ignoreMap":198},[202,544,545,549,552,555],{"class":204,"line":205},[202,546,548],{"class":547},"spNyl","class",[202,550,551],{"class":208}," SendDigest",[202,553,554],{"class":547}," implements",[202,556,557],{"class":208}," ShouldQueue\n",[202,559,560],{"class":204,"line":233},[202,561,562],{"class":212},"{\n",[202,564,565,568,571,574,576,579,582,585,588,591],{"class":204,"line":261},[202,566,567],{"class":547},"    public",[202,569,570],{"class":547}," function",[202,572,573],{"class":216}," __construct",[202,575,383],{"class":212},[202,577,578],{"class":547},"public",[202,580,581],{"class":208}," User",[202,583,584],{"class":212}," $",[202,586,587],{"class":246},"recipient",[202,589,590],{"class":212},")",[202,592,593],{"class":212}," {}\n",[202,595,596],{"class":204,"line":402},[202,597,372],{"emptyLinePlaceholder":371},[202,599,600,602,604,607,610],{"class":204,"line":433},[202,601,567],{"class":547},[202,603,570],{"class":547},[202,605,606],{"class":216}," handle",[202,608,609],{"class":212},"():",[202,611,612],{"class":349}," void\n",[202,614,616],{"class":204,"line":615},6,[202,617,618],{"class":212},"    {\n",[202,620,622,625,628,631,634,636,638,641,643,645,648,650,653,655,658,660,662],{"class":204,"line":621},7,[202,623,624],{"class":212},"        $",[202,626,627],{"class":246},"posts ",[202,629,630],{"class":212},"=",[202,632,633],{"class":208}," Post",[202,635,213],{"class":212},[202,637,240],{"class":216},[202,639,640],{"class":212},"($this->",[202,642,587],{"class":246},[202,644,250],{"class":212},[202,646,647],{"class":216},"latest",[202,649,220],{"class":212},[202,651,652],{"class":216},"limit",[202,654,383],{"class":212},[202,656,657],{"class":349},"10",[202,659,250],{"class":212},[202,661,253],{"class":216},[202,663,399],{"class":212},[202,665,667],{"class":204,"line":666},8,[202,668,372],{"emptyLinePlaceholder":371},[202,670,672],{"class":204,"line":671},9,[202,673,674],{"class":229},"        \u002F\u002F ...\n",[202,676,678],{"class":204,"line":677},10,[202,679,680],{"class":212},"    }\n",[202,682,684],{"class":204,"line":683},11,[202,685,686],{"class":212},"}\n",[184,688,689,690,693,694,292],{},"The reader can be any Eloquent model, such as a ",[188,691,692],{},"User"," or an API client. See ",[464,695,66],{"href":67},[179,697,699],{"id":698},"combining-with-your-own-conditions","Combining with your own conditions",[184,701,702,703,299,706,708],{},"The constraints of the control form one group, so a condition chained ",[296,704,705],{},"before",[188,707,283],{}," stays an AND:",[193,710,712],{"className":195,"code":711,"language":197,"meta":198,"style":198},"Post::where('published', true)->orWhere('featured', true)->controlled()->get();\n\u002F\u002F where (published = 1 or featured = 1) and (the control)\n",[188,713,714,760],{"__ignoreMap":198},[202,715,716,718,720,722,724,726,729,731,733,736,739,741,743,746,748,750,752,754,756,758],{"class":204,"line":205},[202,717,209],{"class":208},[202,719,213],{"class":212},[202,721,291],{"class":216},[202,723,383],{"class":212},[202,725,386],{"class":212},[202,727,728],{"class":389},"published",[202,730,386],{"class":212},[202,732,415],{"class":212},[202,734,735],{"class":212}," true)->",[202,737,738],{"class":216},"orWhere",[202,740,383],{"class":212},[202,742,386],{"class":212},[202,744,745],{"class":389},"featured",[202,747,386],{"class":212},[202,749,415],{"class":212},[202,751,735],{"class":212},[202,753,217],{"class":216},[202,755,220],{"class":212},[202,757,253],{"class":216},[202,759,399],{"class":212},[202,761,762],{"class":204,"line":233},[202,763,764],{"class":229},"\u002F\u002F where (published = 1 or featured = 1) and (the control)\n",[184,766,767,768,299,771,773,774,777,778,780],{},"A condition chained ",[296,769,770],{},"after",[188,772,283],{}," is joined to the whole query, like any Eloquent ",[188,775,776],{},"orWhere()",": an ",[188,779,776],{}," there would bring rows from outside the control. Group your conditions in a closure:",[193,782,784],{"className":195,"code":783,"language":197,"meta":198,"style":198},"Post::controlled()->where(fn (Builder $query) => $query->where('published', true)->orWhere('featured', true))->get();\n",[188,785,786],{"__ignoreMap":198},[202,787,788,790,792,794,796,798,800,803,806,809,811,814,816,819,821,823,826,828,830,832,834,836,838,840,842,844,846,848,850,852,855,857],{"class":204,"line":205},[202,789,209],{"class":208},[202,791,213],{"class":212},[202,793,217],{"class":216},[202,795,220],{"class":212},[202,797,291],{"class":216},[202,799,383],{"class":212},[202,801,802],{"class":547},"fn",[202,804,805],{"class":212}," (",[202,807,808],{"class":208},"Builder",[202,810,584],{"class":212},[202,812,813],{"class":246},"query",[202,815,590],{"class":212},[202,817,818],{"class":212}," =>",[202,820,584],{"class":212},[202,822,813],{"class":246},[202,824,825],{"class":212},"->",[202,827,291],{"class":216},[202,829,383],{"class":212},[202,831,386],{"class":212},[202,833,728],{"class":389},[202,835,386],{"class":212},[202,837,415],{"class":212},[202,839,735],{"class":212},[202,841,738],{"class":216},[202,843,383],{"class":212},[202,845,386],{"class":212},[202,847,745],{"class":389},[202,849,386],{"class":212},[202,851,415],{"class":212},[202,853,854],{"class":212}," true))->",[202,856,253],{"class":216},[202,858,399],{"class":212},[184,860,861],{},"To narrow a list with a rule of your own, such as the posts of one author, intersect it with the controlled list: the control stays inside, so the rule can only narrow it.",[193,863,865],{"className":195,"code":864,"language":197,"meta":198,"style":198},"Post::controlledFor($user, 'update')->where(fn (Builder $query) => $query->whereBelongsTo($author, 'author'));\n",[188,866,867],{"__ignoreMap":198},[202,868,869,871,873,875,877,879,881,883,885,887,889,891,893,895,897,899,901,903,905,907,909,911,913,916,918,921,923,925,927,929],{"class":204,"line":205},[202,870,209],{"class":208},[202,872,213],{"class":212},[202,874,240],{"class":216},[202,876,243],{"class":212},[202,878,247],{"class":246},[202,880,415],{"class":212},[202,882,448],{"class":212},[202,884,390],{"class":389},[202,886,386],{"class":212},[202,888,250],{"class":212},[202,890,291],{"class":216},[202,892,383],{"class":212},[202,894,802],{"class":547},[202,896,805],{"class":212},[202,898,808],{"class":208},[202,900,584],{"class":212},[202,902,813],{"class":246},[202,904,590],{"class":212},[202,906,818],{"class":212},[202,908,584],{"class":212},[202,910,813],{"class":246},[202,912,825],{"class":212},[202,914,915],{"class":216},"whereBelongsTo",[202,917,243],{"class":212},[202,919,920],{"class":246},"author",[202,922,415],{"class":212},[202,924,448],{"class":212},[202,926,920],{"class":389},[202,928,386],{"class":212},[202,930,931],{"class":212},"));\n",[179,933,935],{"id":934},"relations-and-subqueries","Relations and subqueries",[184,937,938,939,942,943,946],{},"Relations, ",[188,940,941],{},"whereHas()"," subqueries, eager loads, lazy loads and route model binding are ",[296,944,945],{},"not controlled"," unless they say so. Each scope works on a relation or a subquery:",[193,948,950],{"className":195,"code":949,"language":197,"meta":198,"style":198},"$user->posts()->controlled()->get();\n\nProject::whereHas('posts', fn (Builder $posts) => $posts->controlled())->get();\n\nUser::with(['posts' => fn ($posts) => $posts->controlled()])->get();\n\nComment::whereIn('post_id', Post::controlledFor($user, 'update')->select('id'))->get();\n",[188,951,952,974,978,1027,1031,1077,1081],{"__ignoreMap":198},[202,953,954,957,959,961,964,966,968,970,972],{"class":204,"line":205},[202,955,956],{"class":212},"$",[202,958,247],{"class":246},[202,960,825],{"class":212},[202,962,963],{"class":216},"posts",[202,965,220],{"class":212},[202,967,217],{"class":216},[202,969,220],{"class":212},[202,971,253],{"class":216},[202,973,399],{"class":212},[202,975,976],{"class":204,"line":233},[202,977,372],{"emptyLinePlaceholder":371},[202,979,980,983,985,988,990,992,994,996,998,1001,1003,1005,1007,1009,1011,1013,1015,1017,1019,1021,1023,1025],{"class":204,"line":261},[202,981,982],{"class":208},"Project",[202,984,213],{"class":212},[202,986,987],{"class":216},"whereHas",[202,989,383],{"class":212},[202,991,386],{"class":212},[202,993,963],{"class":389},[202,995,386],{"class":212},[202,997,415],{"class":212},[202,999,1000],{"class":547}," fn",[202,1002,805],{"class":212},[202,1004,808],{"class":208},[202,1006,584],{"class":212},[202,1008,963],{"class":246},[202,1010,590],{"class":212},[202,1012,818],{"class":212},[202,1014,584],{"class":212},[202,1016,963],{"class":246},[202,1018,825],{"class":212},[202,1020,217],{"class":216},[202,1022,426],{"class":212},[202,1024,253],{"class":216},[202,1026,399],{"class":212},[202,1028,1029],{"class":204,"line":402},[202,1030,372],{"emptyLinePlaceholder":371},[202,1032,1033,1035,1037,1040,1043,1045,1047,1049,1051,1053,1056,1058,1060,1062,1064,1066,1068,1070,1073,1075],{"class":204,"line":433},[202,1034,692],{"class":208},[202,1036,213],{"class":212},[202,1038,1039],{"class":216},"with",[202,1041,1042],{"class":212},"([",[202,1044,386],{"class":212},[202,1046,963],{"class":389},[202,1048,386],{"class":212},[202,1050,818],{"class":212},[202,1052,1000],{"class":547},[202,1054,1055],{"class":212}," ($",[202,1057,963],{"class":246},[202,1059,590],{"class":212},[202,1061,818],{"class":212},[202,1063,584],{"class":212},[202,1065,963],{"class":246},[202,1067,825],{"class":212},[202,1069,217],{"class":216},[202,1071,1072],{"class":212},"()])->",[202,1074,253],{"class":216},[202,1076,399],{"class":212},[202,1078,1079],{"class":204,"line":615},[202,1080,372],{"emptyLinePlaceholder":371},[202,1082,1083,1086,1088,1091,1093,1095,1098,1100,1102,1104,1106,1108,1110,1112,1114,1116,1118,1120,1122,1125,1127,1129,1132,1134,1137,1139],{"class":204,"line":621},[202,1084,1085],{"class":208},"Comment",[202,1087,213],{"class":212},[202,1089,1090],{"class":216},"whereIn",[202,1092,383],{"class":212},[202,1094,386],{"class":212},[202,1096,1097],{"class":389},"post_id",[202,1099,386],{"class":212},[202,1101,415],{"class":212},[202,1103,633],{"class":208},[202,1105,213],{"class":212},[202,1107,240],{"class":216},[202,1109,243],{"class":212},[202,1111,247],{"class":246},[202,1113,415],{"class":212},[202,1115,448],{"class":212},[202,1117,390],{"class":389},[202,1119,386],{"class":212},[202,1121,250],{"class":212},[202,1123,1124],{"class":216},"select",[202,1126,383],{"class":212},[202,1128,386],{"class":212},[202,1130,1131],{"class":389},"id",[202,1133,386],{"class":212},[202,1135,1136],{"class":212},"))->",[202,1138,253],{"class":216},[202,1140,399],{"class":212},[184,1142,1143],{},"A model bound to a route is loaded without control: authorize it through its policy.",[193,1145,1147],{"className":195,"code":1146,"language":197,"meta":198,"style":198},"public function show(Post $post)\n{\n    $this->authorize('view', $post);\n\n    \u002F\u002F ...\n}\n",[188,1148,1149,1170,1174,1199,1203,1208],{"__ignoreMap":198},[202,1150,1151,1153,1155,1158,1160,1162,1164,1167],{"class":204,"line":205},[202,1152,578],{"class":547},[202,1154,570],{"class":547},[202,1156,1157],{"class":216}," show",[202,1159,383],{"class":212},[202,1161,209],{"class":208},[202,1163,584],{"class":212},[202,1165,1166],{"class":246},"post",[202,1168,1169],{"class":212},")\n",[202,1171,1172],{"class":204,"line":233},[202,1173,562],{"class":212},[202,1175,1176,1179,1182,1184,1186,1188,1190,1192,1194,1196],{"class":204,"line":261},[202,1177,1178],{"class":212},"    $this->",[202,1180,1181],{"class":216},"authorize",[202,1183,383],{"class":212},[202,1185,386],{"class":212},[202,1187,334],{"class":389},[202,1189,386],{"class":212},[202,1191,415],{"class":212},[202,1193,584],{"class":212},[202,1195,1166],{"class":246},[202,1197,1198],{"class":212},");\n",[202,1200,1201],{"class":204,"line":402},[202,1202,372],{"emptyLinePlaceholder":371},[202,1204,1205],{"class":204,"line":433},[202,1206,1207],{"class":229},"    \u002F\u002F ...\n",[202,1209,1210],{"class":204,"line":615},[202,1211,686],{"class":212},[179,1213,1215],{"id":1214},"uncontrolled-queries","Uncontrolled queries",[184,1217,1218,1221,1222,1225],{},[188,1219,1220],{},"uncontrolled()"," adds nothing: it states that a query reads every row on purpose, for statistics, seeders or a back office. It reads like ",[188,1223,1224],{},"Post::query()",", and tells a reviewer that the missing control is a choice.",[179,1227,1229],{"id":1228},"deciding-the-rows-of-a-page","Deciding the rows of a page",[184,1231,1232,1233,1236,1237,1240,1241,1243,1244,1247],{},"A page that checks ",[188,1234,1235],{},"@can('update', $post)"," on each row runs one query per row and ability for the perimeters checked in SQL. Decide the whole page in the query that loads it with ",[188,1238,1239],{},"withAbilities()",", after ",[188,1242,283],{}," or ",[188,1245,1246],{},"controlledFor()",":",[193,1249,1251],{"className":195,"code":1250,"language":197,"meta":198,"style":198},"$posts = Post::controlled()\n    ->withAbilities(['view', 'update', 'delete'])\n    ->paginate();\n",[188,1252,1253,1270,1305],{"__ignoreMap":198},[202,1254,1255,1257,1259,1261,1263,1265,1267],{"class":204,"line":205},[202,1256,956],{"class":212},[202,1258,627],{"class":246},[202,1260,630],{"class":212},[202,1262,633],{"class":208},[202,1264,213],{"class":212},[202,1266,217],{"class":216},[202,1268,1269],{"class":212},"()\n",[202,1271,1272,1275,1278,1280,1282,1284,1286,1288,1290,1292,1294,1296,1298,1300,1302],{"class":204,"line":233},[202,1273,1274],{"class":212},"    ->",[202,1276,1277],{"class":216},"withAbilities",[202,1279,1042],{"class":212},[202,1281,386],{"class":212},[202,1283,334],{"class":389},[202,1285,386],{"class":212},[202,1287,415],{"class":212},[202,1289,448],{"class":212},[202,1291,390],{"class":389},[202,1293,386],{"class":212},[202,1295,415],{"class":212},[202,1297,448],{"class":212},[202,1299,423],{"class":389},[202,1301,386],{"class":212},[202,1303,1304],{"class":212},"])\n",[202,1306,1307,1309,1311],{"class":204,"line":261},[202,1308,1274],{"class":212},[202,1310,223],{"class":216},[202,1312,399],{"class":212},[184,1314,1315,1316,1319,1320,1323,1324,1327,1328,1331,1332,1334,1335,1243,1337,1339,1340,292],{},"The query decides each row for each ability, and ",[188,1317,1318],{},"can()",", ",[188,1321,1322],{},"@can"," and ",[188,1325,1326],{},"authorize()"," then answer without SQL. The extra columns never show in ",[188,1329,1330],{},"toArray()"," or the JSON. ",[188,1333,1239],{}," without ",[188,1336,283],{},[188,1338,1246],{}," before it throws ",[188,1341,1342],{},"MissingControlledReaderException",[184,1344,1345,1347,1348,1350,1351,1353,1354,1356,1357,1359,1360,1323,1363,292],{},[188,1346,283],{}," does not decide ",[188,1349,334],{}," by itself: list ",[188,1352,334],{}," in ",[188,1355,1239],{}," when the page checks it. ",[464,1358,150],{"href":151}," covers the others, ",[188,1361,1362],{},"Access::preload()",[188,1364,1365],{},"reachableKeys()",[179,1367,1369],{"id":1368},"good-to-know","Good to know",[478,1371,1372,1383],{},[481,1373,1374,1376,1377,1379,1380,292],{},[188,1375,283],{}," reads ",[188,1378,287],{}," when it runs: do not call it from an event of the user model that the guard fires while it retrieves the user, such as ",[188,1381,1382],{},"retrieved",[481,1384,1385,1386,1319,1388,1323,1390,1392,1393,292],{},"A Laravel Scout search has its own ",[188,1387,283],{},[188,1389,1246],{},[188,1391,1220],{},", and must call one of them. See ",[464,1394,76],{"href":1395},"\u002Fsearch\u002Foverview#searching",[1397,1398,1399],"style",{},"html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}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}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}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 .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}",{"title":198,"searchDepth":205,"depth":233,"links":1401},[1402,1405,1406,1407,1408,1409,1410,1411],{"id":181,"depth":233,"text":182,"children":1403},[1404],{"id":310,"depth":261,"text":311},{"id":327,"depth":233,"text":328},{"id":530,"depth":233,"text":531},{"id":698,"depth":233,"text":699},{"id":934,"depth":233,"text":935},{"id":1214,"depth":233,"text":1215},{"id":1228,"depth":233,"text":1229},{"id":1368,"depth":233,"text":1369},"controlled(), controlledFor() and uncontrolled() filter your Eloquent queries in SQL with the control of the model. A query is controlled only when it says so.","md",null,{},{"title":62,"description":1412},{"loc":63,"lastmod":1418},"2026-11-21T15:24:08+01:00","wVuUekWu8wp6_Bfmuwl1ii_GWPQYPB0GlV9lgXvjK08",[1421,1423],{"title":58,"path":59,"stem":60,"description":1422,"children":-1},"Access::registerPolicies() gives every controlled model a policy built on its control. Learn how it decides, its refusal codes, drafts and business abilities.",{"title":66,"path":67,"stem":68,"description":1424,"children":-1},"The reader is the model a decision is made for. Learn about readers of several types, the decision context, and the decisions kept for a request.",1795277179791]