I need to create a component for Navbar to grab the nav bar links and buttons from the database
I created a component using
php artisan make:component Front/General/lowerHeader
then I edited the component's controller like so
<?php
namespace App\View\Components\Front\General;
use App\Models\NavLink;
use Illuminate\View\Component;
class lowerHeader extends Component
{
public $nav_links;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
$this->nav_links = NavLink::get();
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.front.general.lower-header');
}
}
and rendered it using the following code
<x-front.general.lower-header/>
I used foreach to loop over $nav_links in the view part of the component
I got this error
Undefined variable $nav_links