php - Laravel 应用程序在本地运行良好,但在实时服务器上显示“未定义变量 $header”
问题描述
所以我有一个 Laravel 应用程序,在我的本地主机上它工作正常,没有问题。
然后,当我部署我的应用程序(我通过将 GitHub 存储库直接克隆到 Hostinger(共享主机)中进行部署)时,它显示了以下错误。
下面是 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">
Your browser does not support the video tag.
</video>
{{-- <x-decoration.flame /> --}}
<x-headers.home.video-container />
<x-headers.home.showreel-bar />
</div>
同样,在我的本地主机上一切正常。在我部署 Web 应用程序后的服务器上,它会中断并显示屏幕截图中显示的错误。
找到解决方案
在进行了更多挖掘之后,我偶然发现了这个类似的问题,它解决了我的问题。命名约定是 PascalCase(适用于 app/View/Components 文件夹中的文件夹和文件)。
解决方案
推荐阅读
- roles - BigCommerce:识别登录用户角色
- node.js - 如何等待带有异步请求的 for 循环在 node.js 中完成?
- c# - PHP 和 C# 不同的 Unicode 输出
- ms-access - 更新/更改 ms 访问字段中文件的路径
- java - Jenkins Sonar 插件如何与 SonarQube 集成?
- ibm-cloud-storage - 更新 COS 中已有的 Object
- javascript - 带有jquery表的Javascript Click函数
- python - 英特尔 Distribution for Python 上的 pipenv 环境
- fpga - 指导 Vivado HLS 指令编辑器利用自定义 IP 实现各种功能
- google-cloud-platform - 我们可以通过使用云发布/订阅为同一主题创建不同的订阅来接收多个用户的 gmail 推送通知吗