Var从子视图清空到父视图Laravel

I got a really strange behavior in my views. I have a parent view called "access.blade.php" and child view "survey.blade.php".

I instanciated 2 vars in the parent view which are empty arrays.

I populate them in the child view but when i var_dump them in the parent view after the include of the child view, my var are empty...

here is the parent view :

@extends('template')

@section('title')
    Compile result
@stop

@section('content')

<div id="access" class="container-fluid main-content">

    <div class="row">
        <div class="col-xs-6 col-md-push-3 col-xs-push-3">

            <div class="page-title white-text text-center">
                <h1>Access Report</h1>
            </div>
            <div class="widget-container fluid-height clearfix">

                <?php
                    $session = Sessions::find($params['session_id']);
                    $userNotSeen = [];
                    $userSeen = [];
                ?>

                <div class="heading">
                    <button class="btn btn-success btn-xl pull-right" role="button" data-toggle="modal" data-target="#complianceModal">Compliance</button>
                    Access Report for
                    {{ isset($result->content->display_name) ? $result->content->display_name : $result->content->title }}


                    <p>
                        Journey: {{ $session->location_id != null ? $session->location->city : $session->place }}
                    </p>

                </div>

                <div class="row text-center"></div>

                <div class="row">
                    <div class="col-sm-offset-1 col-sm-10">
                        @if($result != null)
                            @if($result->content_type == 1)
                                @include('contents.partials.access.tasklist')
                            @elseif($result->content_type == 2)
                                @include('contents.partials.access.resources')
                            @elseif($result->content_type == 3)
                                @include('contents.partials.access.survey')
                            @elseif($result->content_type == 4)
                                @include('contents.partials.access.feedback')
                            @elseif($result->content_type == 5)
                                @include('contents.partials.access.memo')
                            @elseif($result->content_type == 6)
                                @include('contents.partials.access.gear')
                            @elseif($result->content_type == 7)
                                @include('contents.partials.access.sinsim')
                            @elseif($result->content_type == 8)
                                @include('contents.partials.access.changr')
                            @endif
                        @else
                            <p class="text-center">{{ $errors }}</p>
                        @endif

                        <pre>
                            {{ var_dump($userNotSeen) }}
                        </pre>
                         <pre>
                            {{ var_dump($userSeen) }}
                        </pre>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
    @include('contents.partials.modal')
@stop

And here is my child view

<table class="table">
    <thead>
    <tr>
        <th>Name</th>
        <th class="text-center">Viewed</th>
        <th class="text-center">Submitted</th>
        <th class="text-center">Personnal Results</th>
    </tr>
    </thead>
    <tbody>
    @if(isset($result->data))
        @forelse($result->data as $key => $value)
            <tr {{ $value->view == 0 ? 'class="notyetseen"' : ''; }}>
                <td>{{ $value->fullname }}</td>
                <td class="text-center">{{ $value->view == 0 ? 'No' : 'Yes' }}</td>
                <td class="text-center">{{ $value->done == 0 ? 'No' : 'Yes' }}</td>
                <td class="text-center">
                    <a href="/manage/{{ $params['session_id'] }}/content/{{ $params['content_id'] }}/{{ $params['content_type'] }}/access/{{ $key }}" class="btn btn-sm btn-success">Get results</a>
                </td>
            </tr>
            <?php
                if($value->view == 0) {
                    array_push($userNotSeen, $key);
                } else {
                    array_push($userSeen, $key);
                }
            ?>
        @empty
            <tr><td colspan="3" class="text-center">{{ $errors }}</td></tr>
        @endforelse
    @else
        <tr><td colspan="3" class="text-center">No participants for this journey</td></tr>
    @endif
    </tbody>
</table>

I have an idea about the why it doesn't work: maybe the parent view is loaded completly before the child view, so my var are not yet populated.

If it is the case, is there any solution?

First of all, never EVER include logic in your templates. Move this logic to your controller and pass results to a view. Templates are only for displaying your data.

If you have to use <?php in your Blade template, you are doing something wrong.

Second, Blade compiles your templates separately. It is not a simple include(__child_template__). That's why while compiling each of your templates, Blade works with completely different variable scopes and $userNotSeen in access.blade.php template is not the same as in your survey.blade.php.