How to pass data to childview in laravel 5
<p>Is there a clean way to pass data to a child view that has been included through blade's @include? Since I know that Im going to be using the same code throughout my website I have decided that a particular variable name must be available for the child view to implement its display.</p>

<p>At first I used something like the following:</p>

<pre><code>foreach($user-&gt;$posts as $requiredNameForChildView){
 @include('mychildView') //child view uses $requiredNameForChildView
}
</code></pre>

<p>But then things got more challenging with other views since I did not always need to loop through an array of objects as before, not allowing me to assign an alias using the 'as' in the foreach. In these cases Im opening a php environment and assigning $requiredNameForChildView before entering the child view but this does not seem to be inline with Laravel's clean code practices.</p>

<p>What are the best practices behind doing something of this sort?</p>