You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel本地运行正常 部署到线上服务器报Undefined variable $header错误

Laravel共享主机部署报错问题

问题描述

我有一个Laravel应用,在本地环境运行完全正常,没有任何问题。
我通过直接克隆GitHub仓库的方式将应用部署到Hostinger共享主机后,出现了Undefined variable $header错误,错误截图如下:
Undefined variable $header错误截图

以下是Intro.php文件代码(我还发现即便在代码中执行dd("random text");,依旧不会输出dd的内容,只会显示上述错误):

<?php

namespace App\View\Components\headers\home;

use App\Models\ApiLink;
use Illuminate\Support\Facades\Http;
use Illuminate\View\Component;

class Intro extends Component
{
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {        
        return view('components.headers.home.intro', [
            'header' => ApiLink::link('translations', 'key=headline'),
            'about' => ApiLink::link('links', 'identifier=about')
        ]);
    }
}

intro.blade.php文件代码如下:

<div class="h-screen w-full flex justify-center items-center relative overflow-hidden -mt-16" style="background: #f9fdfa;">
    <div class="-mt-80 lg:-mt-36 text-center relative z-10">
        <h1 class="font-light text-4xl sm:text-6xl" id="home-headline">
            {{ $header[0]['value'] }}
        </h1>

        <x-button 
            to="pages.about" 
            :text="$about[0]['page_name']"
            extraStyling="mt-5" />
    </div>

    <video class="z-0 absolute -bottom-32 left-1/2 transform -translate-x-1/2 hidden md:block" style="width: 1200px" id="flame-video" muted loop autoplay>
        <source src="{{ asset('videos/flame3.webmhd.webm') }}" type="video/webm">
        您的浏览器不支持video标签。
    </video>

    {{-- <x-decoration.flame /> --}}

    <x-headers.home.video-container />
    
    <x-headers.home.showreel-bar />
</div>

该应用在本地环境完全正常,部署到服务器后就报错显示上述问题。

解决方案

经过进一步排查,故障触发原因是:app/View/Components目录下的所有文件夹和文件都需要遵循PascalCase命名规范,本地环境大小写不敏感所以无报错,服务器操作系统大小写敏感,因此部署后触发错误。

内容的提问来源于stack exchange,提问作者Rammah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 08:09:04