How to Pass a Variable to Include in Laravel
In this lesson, we will see how to pass a variable to include in Laravel.
Sometimes, we want to pass a variable to the included file and display it, so how can we do that?
Pass variable to include
To do that, as the code below shows, we pass an array with the key and the value and later display it inside the include.
//pass the variable to the include@include('alerts.blade.php',['alert' => 'success']);
//display the message inside the include{{ $alert }}