如何将 laravel 个组件放在单独的文件夹中
How to put laravel components within separate folders
当我制作新组件时,我希望在制作时在根目录中拥有像 Modal 这样的基本组件:
app/View/Components/Modal.php
然后我想要类似的东西
app/View/Components/Modals/Login.php
app/View/Components/Modals/Register.php
app/View/Components/Modals/ResetPassword.php
我怎么 use/call 这些组件就像根文件夹中的组件一样? (组件作为根文件夹)
<x-modal></x-modal>
- 工作正常
但是 <x-login></x-login>
或 <x-modals-login></x-modals-login>
不起作用。有没有可以像这样工作的东西?
documentation 对此进行了解释:
If the component class is nested deeper within the App\View\Components
directory, you may use the . character to indicate directory nesting. For example, if we assume a component is located at App\View\Components\Inputs\Button.php
, we may render it like so:
<x-inputs.button/>
所以在你的情况下,这将是:
<x-modals.login>
当我制作新组件时,我希望在制作时在根目录中拥有像 Modal 这样的基本组件:
app/View/Components/Modal.php
然后我想要类似的东西
app/View/Components/Modals/Login.php
app/View/Components/Modals/Register.php
app/View/Components/Modals/ResetPassword.php
我怎么 use/call 这些组件就像根文件夹中的组件一样? (组件作为根文件夹)
<x-modal></x-modal>
- 工作正常
但是 <x-login></x-login>
或 <x-modals-login></x-modals-login>
不起作用。有没有可以像这样工作的东西?
documentation 对此进行了解释:
If the component class is nested deeper within the
App\View\Components
directory, you may use the . character to indicate directory nesting. For example, if we assume a component is located atApp\View\Components\Inputs\Button.php
, we may render it like so:
<x-inputs.button/>
所以在你的情况下,这将是:
<x-modals.login>