{"_path":"/knowledge-base/ltstack-crud-macros","_draft":false,"_partial":false,"_empty":false,"title":"Litstack: Use crud macros","description":"To reuse parts of crud or form configs, you may use crud macros.","excerpt":{"type":"root","children":[{"type":"element","tag":"h1","props":{"id":"litstack-use-crud-macros"},"children":[{"type":"text","value":"Litstack: Use crud macros"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"To reuse parts of crud or form configs, you may use crud macros."}]},{"type":"element","tag":"h2","props":{"id":"macro-directory"},"children":[{"type":"text","value":"Macro directory"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Create a new directory "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"lit/app/Macros"}]},{"type":"text","value":" for your macro files."}]},{"type":"element","tag":"h2","props":{"id":"macro-files"},"children":[{"type":"text","value":"Macro files"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Create a macro file i.e. "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"lit/app/Macros/MyMacro.php"}]},{"type":"text","value":":"}]},{"type":"element","tag":"code","props":{"code":"<?php\nnamespace Lit\\Macros;\nuse Ignite\\Crud\\BaseForm;\nclass MyMacro\n{\n    public function register()\n    {\n        BaseForm::macro('myMacro', function () {\n            $this->input('my_input');\n        });\n    }\n}\n","language":"php"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"<?php\nnamespace Lit\\Macros;\nuse Ignite\\Crud\\BaseForm;\nclass MyMacro\n{\n    public function register()\n    {\n        BaseForm::macro('myMacro', function () {\n            $this->input('my_input');\n        });\n    }\n}\n"}]}]}]},{"type":"element","tag":"h2","props":{"id":"register-macros"},"children":[{"type":"text","value":"Register macros"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Register your macros in the "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"lit/app/Providers/LitstackServiceProvider"}]},{"type":"text","value":":"}]},{"type":"element","tag":"code","props":{"code":"use Lit\\Macros\\MyMacro;\n\npublic function register()\n{\n    (new MyMacro)->register();\n}\n","language":"php"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"use Lit\\Macros\\MyMacro;\n\npublic function register()\n{\n    (new MyMacro)->register();\n}\n"}]}]}]},{"type":"element","tag":"h2","props":{"id":"use-macros"},"children":[{"type":"text","value":"Use macros"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Use your macro in any crud or form config"}]},{"type":"element","tag":"code","props":{"code":"$form->myMacro();\n","language":"php"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"$form->myMacro();\n"}]}]}]}]},"public":true,"body":{"type":"root","children":[{"type":"element","tag":"h1","props":{"id":"litstack-use-crud-macros"},"children":[{"type":"text","value":"Litstack: Use crud macros"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"To reuse parts of crud or form configs, you may use crud macros."}]},{"type":"element","tag":"h2","props":{"id":"macro-directory"},"children":[{"type":"text","value":"Macro directory"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Create a new directory "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"lit/app/Macros"}]},{"type":"text","value":" for your macro files."}]},{"type":"element","tag":"h2","props":{"id":"macro-files"},"children":[{"type":"text","value":"Macro files"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Create a macro file i.e. "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"lit/app/Macros/MyMacro.php"}]},{"type":"text","value":":"}]},{"type":"element","tag":"code","props":{"code":"<?php\nnamespace Lit\\Macros;\nuse Ignite\\Crud\\BaseForm;\nclass MyMacro\n{\n    public function register()\n    {\n        BaseForm::macro('myMacro', function () {\n            $this->input('my_input');\n        });\n    }\n}\n","language":"php"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"<?"}]},{"type":"element","tag":"span","props":{"style":{"color":"#79C0FF"}},"children":[{"type":"text","value":"php"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"namespace"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FFA657"}},"children":[{"type":"text","value":"Lit\\Macros"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":";"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"use"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#79C0FF"}},"children":[{"type":"text","value":"Ignite\\Crud\\BaseForm"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":";"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"class"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FFA657"}},"children":[{"type":"text","value":"MyMacro"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"{"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"    "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"public"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"function"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#D2A8FF"}},"children":[{"type":"text","value":"register"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"()"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"    {"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"        "}]},{"type":"element","tag":"span","props":{"style":{"color":"#79C0FF"}},"children":[{"type":"text","value":"BaseForm"}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"::"}]},{"type":"element","tag":"span","props":{"style":{"color":"#D2A8FF"}},"children":[{"type":"text","value":"macro"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"("}]},{"type":"element","tag":"span","props":{"style":{"color":"#A5D6FF"}},"children":[{"type":"text","value":"'myMacro'"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":", "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"function"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" () {"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"            "}]},{"type":"element","tag":"span","props":{"style":{"color":"#79C0FF"}},"children":[{"type":"text","value":"$this"}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"->"}]},{"type":"element","tag":"span","props":{"style":{"color":"#D2A8FF"}},"children":[{"type":"text","value":"input"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"("}]},{"type":"element","tag":"span","props":{"style":{"color":"#A5D6FF"}},"children":[{"type":"text","value":"'my_input'"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":");"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"        });"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"    }"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"}"}]}]}]}]}]},{"type":"element","tag":"h2","props":{"id":"register-macros"},"children":[{"type":"text","value":"Register macros"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Register your macros in the "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"lit/app/Providers/LitstackServiceProvider"}]},{"type":"text","value":":"}]},{"type":"element","tag":"code","props":{"code":"use Lit\\Macros\\MyMacro;\n\npublic function register()\n{\n    (new MyMacro)->register();\n}\n","language":"php"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"use"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#79C0FF"}},"children":[{"type":"text","value":"Lit\\Macros\\MyMacro"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":";"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"public"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"function"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#D2A8FF"}},"children":[{"type":"text","value":"register"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"()"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"{"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"    ("}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"new"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":" "}]},{"type":"element","tag":"span","props":{"style":{"color":"#79C0FF"}},"children":[{"type":"text","value":"MyMacro"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":")"}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"->"}]},{"type":"element","tag":"span","props":{"style":{"color":"#D2A8FF"}},"children":[{"type":"text","value":"register"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"();"}]}]},{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"}"}]}]}]}]}]},{"type":"element","tag":"h2","props":{"id":"use-macros"},"children":[{"type":"text","value":"Use macros"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Use your macro in any crud or form config"}]},{"type":"element","tag":"code","props":{"code":"$form->myMacro();\n","language":"php"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"element","tag":"span","props":{"class":"line"},"children":[{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"$form"}]},{"type":"element","tag":"span","props":{"style":{"color":"#FF7B72"}},"children":[{"type":"text","value":"->"}]},{"type":"element","tag":"span","props":{"style":{"color":"#D2A8FF"}},"children":[{"type":"text","value":"myMacro"}]},{"type":"element","tag":"span","props":{"style":{"color":"#C9D1D9"}},"children":[{"type":"text","value":"();"}]}]}]}]}]}],"toc":{"title":"","searchDepth":2,"depth":2,"links":[{"id":"macro-directory","depth":2,"text":"Macro directory"},{"id":"macro-files","depth":2,"text":"Macro files"},{"id":"register-macros","depth":2,"text":"Register macros"},{"id":"use-macros","depth":2,"text":"Use macros"}]}},"_type":"markdown","_id":"content:04.knowledge-base:ltstack-crud-macros.md","_source":"content","_file":"04.knowledge-base/ltstack-crud-macros.md","_extension":"md"}