return two views in a Laravel 5.5 driver

0

I would like to know if I can return two views in a laravel driver, the version I have is 5.5 and I am trying this way:

Driver:

            $info1 = [
                'datos'     => $datos1,
                'nombre'    => $nombre
            ];

            $info2 = [
                'datos'    => $datos2,
                'estado'   => $estado
            ];   

            $documentos1 = view('App.documentos1',['info' => $info1]);
            $documentos2 = view('App.documentos2',['info' => $info2]);

            $return = [
                'documentos1' => $documentos1,
                'documentos2' => $documentos2
            ];

            return $return;

View 1:

    <div class="col-md-12 panel-grids " style="margin-top:10px;">
   <hr>
    <div class="panel panel-default">
        <div class="panel-heading"> <h3 class="panel-title"><b class="fa fa-money"></b> <b>Lista de Documento</b></h3> </div>
        <div class="panel-body table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Documento</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                @foreach ($datos as $key => $value) 
                    <tr class="warning">
                        <th scope="row">1</th>
                        <td style="width: 5px;text-align: left;">
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
     <hr>
</div>

Vista 2:

    <div class="col-md-12 panel-grids " style="margin-top:10px;">
   <hr>
    <div class="panel panel-default">
        <div class="panel-heading"> <h3 class="panel-title"><b class="fa fa-money"></b> <b>Lista de Documento Especiales</b></h3> </div>
        <div class="panel-body table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Documento</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                @foreach ($datos as $key => $value) 
                    <tr class="warning">
                        <th scope="row">1</th>
                        <td style="width: 5px;text-align: left;">
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
     <hr>
</div>

Template:

<div class="stats-title">
    <h4 class="title">Documentación</h4>
    <hr>
</div>
<div class="row">
    <div class="col-xs-12 col-md-12 ">
        <div id='formulario' class="form-body">
            <div class="form-horizontal">
                <div class="well">

                </div>
                <div class="col-md-8">
                    {!! $sedes !!}


                   <div id="Documentos1" class="col-md-12"></div>
                </div>
                <div id="gps" class="col-md-4"></div>
                <div id="Documentos2" class="col-md-12"></div>
            </div>
        </div>
    </div>
</div>
<div class="stats-body"> </div>
<div class="clearfix"> </div>

I need to do so since the two lists go in separate parts of the template and by jquery I will locate the returned values but when I return the variable $return; is empty but I return the variable $documentos1 or $documentos2 , if he returns his sight.

    
asked by Andrés 30.11.2017 в 14:52
source

1 answer

1

Why do not you compose the view using a blade?

With @include('plantilla') you can include other "views" (templates).

Let's give an example:

template.blade.php

@include('plantilla1')
@include('plantilla2')

<!-- resto de html -->

Controller.php

$info1 = [
    'datos'     => $datos1,
    'nombre'    => $nombre
 ];

$info2 = [
    'datos'    => $datos2,
    'estado'   => $estado
];   

return view('template')
                        ->with('info1', $info1)
                        ->with('info2', $info2);

In this way you will have both variables available in the templates involved.

You can review the documentation for more information: link

    
answered by 30.11.2017 в 15:09