laravel component class was ignored

Viewed 95

I made a laravel component using command php artisan make:component TestComponent

So, two files(resources/view/component/test-component.blade.php and app/View/Components/TestComponent.php) was created.

However, test-component.blade.php file was worked fine, but TestComponent.php file was ignored.

I check this issue to change render method like that.

<?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
    }
}

The fake view name(foofoofoofoofoo) was ignored and test-component view was rendered.

And id variable doesn't delivered to view when I use default value like <x-test-component /> (<x-test-component id='abc' /> was worked fine.)

I try to register manually in boot method on AppServiceProvider.php

    public function boot()
    {
        Blade::component('test-component', App\View\Components\TestComponent::class);
    }

But it doesn't work too.

php artisan clear:view, php artisan cache:clear, composer dump doesn't work on this issue.

1 Answers

I solved this problem to update laravel version to 8.38.0 and run php artisan view:clear

Related