【问题标题】:Laravel 7 Unable to locate a class or view for component on production environmentLaravel 7无法在生产环境中找到组件的类或视图
【发布时间】:2020-08-17 13:56:31
【问题描述】:

在设置新的 droplet 并部署我的 laravel 项目后,我的项目遇到了问题。 当我尝试访问使用 laravel 7 组件的页面时,出现以下错误:

Unable to locate a class or view for component [vbMenuItem].

经过一些调试,我无法弄清楚为什么会发生此错误,在我的本地环境中它可以正常工作,并且在作为备份运行的旧生产环境中,相同的代码库也可以正常工作。

代码非常简单:

<ul class="navbar-nav ml-auto">
     <x-vbMenuItem permission="view distributors" route="distributor" label="Distributors" asset="icons/Distributors.svg"/>
</ul>

以及组件本身:

class vbMenuItem extends Component
{
    public $permission;
    public $route;
    public $asset;
    public $label;

    /**
     * Create a new component instance.
     *
     * @param $permission
     * @param $route
     * @param $asset
     * @param $label
     */
    public function __construct($permission, $route, $asset, $label)
    {
        $this->permission = $permission;
        $this->route = $route;
        $this->asset = $asset;
        $this->label = $label;
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return View|string
     */
    public function render()
    {
        return view('components.vb-menu-item');
    }
}

有人遇到过这个问题吗?如果是这样,我可以稍微推动一下正确的方向。

【问题讨论】:

  • 如您所见 here,Blade 组件标签以字符串 x- 开头,后跟组件类的 kebab 案例名称,因此在您的案例中它将是 &lt;x-vb-menu-item/&gt;,此外您的类应该是帕斯卡大小写,所以VbMenuItem 而不是vbMenuItem
  • 感谢您的评论,我将看看刀片组件的编码标准。但这真的会影响应用程序的功能吗?如果是这样,奇怪的是它确实在本地和备份服务器上工作,但在新创建的服务器上却不行。
  • 这个issue有评论,可能是问题的原因。

标签: laravel laravel-7


【解决方案1】:

我遇到了和你一样的错误,就我而言,这是因为在 linux 中它是区分大小写的,我通过将 /app/View/Components/icons.php 更改为 Icons.php 来解决它。

无法找到组件 [icons] 的类或视图。 (查看:/var/www/html/mekiot/resources/views/livewire/devices/team-group-views-list.blade.php)(查看:/var/www/html/mekiot/resources/views/livewire/ devices/team-group-views-list.blade.php)

【讨论】:

    猜你喜欢
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 2019-03-30
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多