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.
At first I used something like the following:
foreach($user->$posts as $requiredNameForChildView){
@include('mychildView') //child view uses $requiredNameForChildView
}
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.
What are the best practices behind doing something of this sort?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire