我有匿名组件resources\views\components\homepage\feedback.blade.php来在主页上呈现反馈。从一开始它只是html。然后我决定连接Class文件。我已经有了另一个 View Class 组件,我只是手动复制它而不是使用 artisan 命令。
App\View\Components\Feedback.php
namespace App\View\Components;
use Illuminate\View\Component;
use App\Models\Feedback;
class Feedback extends Component
{
public $feedbacks;
public function __construct()
{
$this->feedbacks = Feedback::wherePublished(true)->take(5);
}
public function render()
{
return view('components.homepage.feedback');
}
}
然后视图文件中的 {{ dd($feedbacks) }} 给我错误,提示未定义此变量。
Undefined variable: feedbacks (View: C:\laragon\www\lara7\resources\views\components\homepage\feedback.blade.php)
如果我尝试使用 artisan 命令创建测试组件并将此代码放入其中,它就可以工作,但我无法将其重命名回反馈类。它给我错误
Symfony\Component\ErrorHandler\Error\FatalError
Cannot declare class App\View\Components\Feedback because the name is already in use
但是旧班级已经删除了,所以我不明白出了什么问题。
View Class 和 Blade 组件之间似乎有一些隐藏的链接,需要删除。但是这个链接在哪里?
繁星点点滴滴
Smart猫小萌
紫衣仙女
慕容森