Php 已忽略laravel组件类
我使用命令Php 已忽略laravel组件类,php,laravel,Php,Laravel,我使用命令php-artisan-make:component-TestComponent 因此,创建了两个文件(resources/view/component/TestComponent.blade.php和app/view/Components/TestComponent.php) 然而,TestComponent.blade.php文件工作正常,但忽略了TestComponent.php文件 我检查此问题以更改渲染方法 <?php namespace App\View\Compo
php-artisan-make:component-TestComponent
因此,创建了两个文件(resources/view/component/TestComponent.blade.php
和app/view/Components/TestComponent.php
)
然而,TestComponent.blade.php
文件工作正常,但忽略了TestComponent.php
文件
我检查此问题以更改渲染方法
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class TestComponent extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public $id;
public function __construct($id="test")
{
$this->id = $id;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|string
*/
public function render()
{
return view('components.foofoofoofoofoo'); // fake view name
}
}
但它也不起作用
php-artisan-clear:view
,php-artisan-cache:clear
,composer-dump
无法解决此问题。我解决了此问题,将laravel版本更新为8.38.0,并运行php-artisan-view:clear
在哪里传递id
,在哪里调用TestComponent
?请share@A.ANoman使用测试组件时,laravel会自动调用TestComponent。很高兴看到您的努力。
public function boot()
{
Blade::component('test-component', App\View\Components\TestComponent::class);
}