I have been running into this very weird issue with Laravel.
I had a problem where one of my component views was not able to read the variables defined in its class. It was kind of strange because I have several components running in my project and they all worked fine, except for this one.
So I created a fresh Laravel project to test some things out (Wanted to check if the problem was on my end, maybe I somehow messed up the project files).
I created a new component on a blank project using php artisan make:component Test
Then I simply added a test variable to the class component like so:
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class Test extends Component
{
public $test;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
$this->test = "testing";
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|string
*/
public function render()
{
return view('components.test');
}
}
And tried to access it over in the view like so:
<div>
<p> {{$test}} </p>
</div>
For some reason, this is not working and I can't figure out why. It just says that $test is undefined.
Perhaps I should point out, I am a beginner in Laravel, so excuse me if I am making some obvious mistake. It just seemed weird that this is not working on a blank project.
Thank you in advance.

return view('components.test', ['test' => $test]);$this->testbecause$testwas undefined. It still doesn't work (Same problem). Also, according to the docs, aren't public variables supposed to be available to the view by default? Meaning, I don't have to explicitly pass them like in the example you provided?