Laravel本地运行正常 部署到线上服务器报Undefined variable $header错误
Laravel共享主机部署报错问题
问题描述
我有一个Laravel应用,在本地环境运行完全正常,没有任何问题。
我通过直接克隆GitHub仓库的方式将应用部署到Hostinger共享主机后,出现了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
相关产品推荐
相关产品推荐

