laravel - Laravel 组件没有在共享主机中获取我的方法
问题描述
我刚刚将一个在我的本地主机上运行良好的项目迁移到共享主机,我的组件突然没有得到我给它们的方法,我的视图中出现了如下错误:
Undefined variable: CatPromo
这是我的组件:
<?php
namespace App\View\Components;
use Illuminate\View\Component;
use App\Categories;
class promo extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|string
*/
public function render()
{
return view('components.promo');
}
public function CatPromo()
{
$Categories = Categories::all();
return $Categories;
}
}
更新:我删除了App\View\Components\promo.php
,看看它是否可以通过抛出错误来帮助我,似乎他甚至没有检测到控制器。
解决方案
文档说:您应该在其类构造函数中定义组件所需的数据。
public function __construct($CatPromo)
{
// use as variable
$this->CatPromo = $CatPromo;
}
// use as method
public function CatPromo()
{
$Categories = Categories::all();
return $Categories;
}
在刀片模板中:
@foreach($CatPromo() as $key => $Categorie)
推荐阅读
- angularjs - angularjs登录中的类型错误不是函数
- scala - Akka 投影测试总是失败
- git - git - 如果没有其他分支,如何删除本地 master
- autodesk-forge - Autodesk forge 转换扩展打开/关闭 X、Y、Z 轴
- node.js - 如何使用 Traefik 让外部服务接受来自 Docker 中的内部服务的请求
- scheduled-tasks - 如何运行监控应用程序?
- autodesk-forge - Forge viewer 显示异常
- ios - 我们如何从 swift 包中访问 .a 文件
- css - CSS3 - 渐进式缩放高度/最小高度
- jvm - Hazelcast 正在使用大量 JVM 线程