[{"data":1,"prerenderedAt":331},["ShallowReactive",2],{"article:\u002Farticles\u002Fskinny-controllers-fat-models":3,"article-surround:\u002Farticles\u002Fskinny-controllers-fat-models":322},{"id":4,"title":5,"body":6,"date":310,"description":311,"draft":312,"extension":313,"meta":314,"navigation":113,"path":315,"seo":316,"stem":317,"tags":318,"__hash__":321},"articles\u002Farticles\u002Fskinny-controllers-fat-models.md","Skinny Controllers, Fat Models",{"type":7,"value":8,"toc":308},"minimark",[9,13,16,19,304],[10,11,12],"p",{},"\"Skinny Controllers, Fat Models\" is a software design guideline commonly associated with the MVC (Model-View-Controller) architectural pattern. It suggests that the application's business logic should be placed in the model layer rather than in the controller. The idea is that the controller should remain lightweight, focusing primarily on handling user input, managing views, and returning a response.",[10,14,15],{},"This approach promotes various good practices, such as separation of concerns, reusability, simplified testing, loose coupling, and improved code organisation and readability.",[10,17,18],{},"This approach is commonly found in frameworks that use the Active Record pattern, such as Laravel, because models themselves are responsible for persistence as well as business logic, but this same reasoning could be applied to another layer, such as service-layer, command-layer, domain-layer, etc.",[20,21,26],"pre",{"className":22,"code":23,"language":24,"meta":25,"style":25},"language-php shiki shiki-themes github-dark github-light","\u002F\u002F app\\Models\\Player.php\nclass Player extends Model\n{\n    ...\n    public function move(Location $location)\n    {\n        \u002F\u002F Do some logic to move player\n    }\n\n    public function move(AttackableObject $object)\n    {\n        \u002F\u002F Do some logic to attack object\n    }\n    ...\n}\n\n\u002F\u002F app\\Http\\Controllers\\GameController.php\nclass GameController extends Controller\n{\n    public function __invoke()\n    {\n        $player = Player::first();\n        $location == Location::first();\n        $enemy = Enemy::first();\n\n        $player->move($location);\n        $player->attack($enemy);\n    }\n}\n","php","",[27,28,29,38,55,62,68,90,96,102,108,115,132,137,143,148,153,159,164,170,183,188,201,206,226,244,261,266,281,294,299],"code",{"__ignoreMap":25},[30,31,34],"span",{"class":32,"line":33},"line",1,[30,35,37],{"class":36},"si27w","\u002F\u002F app\\Models\\Player.php\n",[30,39,41,45,49,52],{"class":32,"line":40},2,[30,42,44],{"class":43},"spKkM","class",[30,46,48],{"class":47},"sqoU-"," Player",[30,50,51],{"class":43}," extends",[30,53,54],{"class":47}," Model\n",[30,56,58],{"class":32,"line":57},3,[30,59,61],{"class":60},"shWlK","{\n",[30,63,65],{"class":32,"line":64},4,[30,66,67],{"class":43},"    ...\n",[30,69,71,74,77,80,83,87],{"class":32,"line":70},5,[30,72,73],{"class":43},"    public",[30,75,76],{"class":43}," function",[30,78,79],{"class":47}," move",[30,81,82],{"class":60},"(",[30,84,86],{"class":85},"sTU5a","Location",[30,88,89],{"class":60}," $location)\n",[30,91,93],{"class":32,"line":92},6,[30,94,95],{"class":60},"    {\n",[30,97,99],{"class":32,"line":98},7,[30,100,101],{"class":36},"        \u002F\u002F Do some logic to move player\n",[30,103,105],{"class":32,"line":104},8,[30,106,107],{"class":60},"    }\n",[30,109,111],{"class":32,"line":110},9,[30,112,114],{"emptyLinePlaceholder":113},true,"\n",[30,116,118,120,122,124,126,129],{"class":32,"line":117},10,[30,119,73],{"class":43},[30,121,76],{"class":43},[30,123,79],{"class":47},[30,125,82],{"class":60},[30,127,128],{"class":85},"AttackableObject",[30,130,131],{"class":60}," $object)\n",[30,133,135],{"class":32,"line":134},11,[30,136,95],{"class":60},[30,138,140],{"class":32,"line":139},12,[30,141,142],{"class":36},"        \u002F\u002F Do some logic to attack object\n",[30,144,146],{"class":32,"line":145},13,[30,147,107],{"class":60},[30,149,151],{"class":32,"line":150},14,[30,152,67],{"class":43},[30,154,156],{"class":32,"line":155},15,[30,157,158],{"class":60},"}\n",[30,160,162],{"class":32,"line":161},16,[30,163,114],{"emptyLinePlaceholder":113},[30,165,167],{"class":32,"line":166},17,[30,168,169],{"class":36},"\u002F\u002F app\\Http\\Controllers\\GameController.php\n",[30,171,173,175,178,180],{"class":32,"line":172},18,[30,174,44],{"class":43},[30,176,177],{"class":47}," GameController",[30,179,51],{"class":43},[30,181,182],{"class":47}," Controller\n",[30,184,186],{"class":32,"line":185},19,[30,187,61],{"class":60},[30,189,191,193,195,198],{"class":32,"line":190},20,[30,192,73],{"class":43},[30,194,76],{"class":43},[30,196,197],{"class":85}," __invoke",[30,199,200],{"class":60},"()\n",[30,202,204],{"class":32,"line":203},21,[30,205,95],{"class":60},[30,207,209,212,215,217,220,223],{"class":32,"line":208},22,[30,210,211],{"class":60},"        $player ",[30,213,214],{"class":43},"=",[30,216,48],{"class":85},[30,218,219],{"class":43},"::",[30,221,222],{"class":47},"first",[30,224,225],{"class":60},"();\n",[30,227,229,232,235,238,240,242],{"class":32,"line":228},23,[30,230,231],{"class":60},"        $location ",[30,233,234],{"class":43},"==",[30,236,237],{"class":85}," Location",[30,239,219],{"class":43},[30,241,222],{"class":47},[30,243,225],{"class":60},[30,245,247,250,252,255,257,259],{"class":32,"line":246},24,[30,248,249],{"class":60},"        $enemy ",[30,251,214],{"class":43},[30,253,254],{"class":85}," Enemy",[30,256,219],{"class":43},[30,258,222],{"class":47},[30,260,225],{"class":60},[30,262,264],{"class":32,"line":263},25,[30,265,114],{"emptyLinePlaceholder":113},[30,267,269,272,275,278],{"class":32,"line":268},26,[30,270,271],{"class":60},"        $player",[30,273,274],{"class":43},"->",[30,276,277],{"class":47},"move",[30,279,280],{"class":60},"($location);\n",[30,282,284,286,288,291],{"class":32,"line":283},27,[30,285,271],{"class":60},[30,287,274],{"class":43},[30,289,290],{"class":47},"attack",[30,292,293],{"class":60},"($enemy);\n",[30,295,297],{"class":32,"line":296},28,[30,298,107],{"class":60},[30,300,302],{"class":32,"line":301},29,[30,303,158],{"class":60},[305,306,307],"style",{},"html pre.shiki code .si27w, html code.shiki .si27w{--shiki-default:#6A737D;--shiki-light:#6A737D}html pre.shiki code .spKkM, html code.shiki .spKkM{--shiki-default:#F97583;--shiki-light:#D73A49}html pre.shiki code .sqoU-, html code.shiki .sqoU-{--shiki-default:#B392F0;--shiki-light:#6F42C1}html pre.shiki code .shWlK, html code.shiki .shWlK{--shiki-default:#E1E4E8;--shiki-light:#24292E}html pre.shiki code .sTU5a, html code.shiki .sTU5a{--shiki-default:#79B8FF;--shiki-light:#005CC5}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 .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);}",{"title":25,"searchDepth":40,"depth":40,"links":309},[],"2024-03-17","Keeping controllers lightweight by moving business logic out of them - what the rule buys you in testing and reuse, and where a service or domain layer fits instead.",false,"md",{},"\u002Farticles\u002Fskinny-controllers-fat-models",{"title":5,"description":311},"articles\u002Fskinny-controllers-fat-models",[24,319,320],"laravel","architecture","eiraLIYuMcC_xlpgDXIxyV6vOzsx2yIg_0qKrXfdO98",[323,327],{"title":324,"path":325,"stem":326,"children":-1},"Simplify Your Build Process with Makefile","\u002Farticles\u002Fsimplify-your-build-process-with-makefile","articles\u002Fsimplify-your-build-process-with-makefile",{"title":328,"path":329,"stem":330,"children":-1},"Understanding Service Containers in PHP","\u002Farticles\u002Funderstanding-service-containers-in-php","articles\u002Funderstanding-service-containers-in-php",1782332464073]