我有一个奇怪的问题,我正在为要在组件中显示的 Laravel 7 组件设置一个变量。虽然它在我的开发环境(MacOS 上的 MAMP)中工作,但当我将它加载到 HostGator 中的共享主机时它不起作用。在 HostGator 中,它会引发 500 错误,抱怨“未定义的变量:page_title”。
关于这里可能发生什么的任何想法?
应用程序/组件/布局/ContentHeader.php
class ContentHeader extends Component
{
public $page_title;
public $breadcrumbs = [];
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
$this->page_title = 'Some title';
$crumb = new \stdClass();
$crumb->label = 'Home';
$crumb->active = false;
$this->breadcrumbs[] = $crumb;
$crumb = new \stdClass();
$crumb->label = $this->page_title;
$crumb->active = true;
$this->breadcrumbs[] = $crumb;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|string
*/
public function render()
{
return view('components.layout.content-header');
}
}
<!-- Resources/views/components/layout/content-header.blade.php -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">{{ $page_title }}</h1>
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
@foreach ($breadcrumbs as $crumb)
@if (!$crumb->active)
<li class="breadcrumb-item"><a href="#">{{ $crumb->label }}</a></li>
@else
<li class="breadcrumb-item active">{{ $crumb->label }}</li>
@endif
@endforeach
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->```