Hi ARESLAX,
please try the following
class PagesController extends Controller
{
protected $links;
public function __construct()
{
$this->links = [
['Home','/'],
['About','/about'],
['Contact','/contact']
];
}
public function home()
{
return view('welcome','links'=>$this->links);
}
public function about()
{
return view('about',['links'=>[$this->links]]);
}
}
you could also stick this in the controller.php file so it will be available in all your controllers
I would also suggest having a read of the following https://laravel.com/docs/5.8/views#view-composers as I think this might be a nicer option for something like links as they are injected into every page without having to specify them in every controller
Thank you! That works as intended.
I'm just getting up to speed with PHP classes and Laravel, and I will read the link you suggested.
I appreciate your attention and solution.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community