samedi 27 février 2016

How to pass data to childview in laravel 5

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?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1WQQGtG
via IFTTT

Aucun commentaire:

Enregistrer un commentaire