I have created a Laravel Component and it works fine on my local machine, but when I deploy the project to the hosting it stops working there and the error Undefined variable $navbar
occurs.
app\View\Components
class navbar extends Component
{
/**
* Create a new component instance.
*/
public function __construct(public $navbar = [])
{
$this->navbar = config('navbar');
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.navbar');
}
}
When I use the component <x-navbar ></x-navbar>
an error occurs, but if I add the attribute <x-navbar :navbar="config('navbar')"></x- navbar>
the error disappears.
I have a feeling that the component class is ignored on the hosting, since even dd('test')
does not work if it is added to __construct
. There are no such problems on the local machine.
The project was deployed on www.hostinger.com according to their instructions.