How to pass data searched by a view back to the view itself

2

I need to search a database through a view (Laravel Blade). The data obtained, stored in an array, need to display on the page itself called the database. I'm not getting the array return with such data, because I do not know how to handle the array within the view block that expects this response.

I explain:

The view that prepares the query to the database has a form with a Submit button. This action triggers a Controller method that goes to the database, searches the data, and returns an array. The data exists, the array is populated. They are the following steps:

First, the view and the form. Filename: listar.blade.php:

@extends ('PrincipalView')
@corpo
<form name="frmTSPesquisar" 
action="{{    action('TSController@pesquisarExecutar') }}" 
method="GET" role="form">
Busca: <input list="files" placeholder="20000">
<datalist id="files">
<option>20000</option>          
</datalist>         
<button type="submit">Pesquisar</button>
</form>
@stop

See that the form's Action tag already forwards what Submit will cause.

In the TSController.php page where the provoked method resides, I have the following code:

public function pesquisarExecutar(Request $request) {
    $resultado=DB::table('tabts')
            ->join('tabfiles', 'tabts.file_tabfiles', '=', 'tabfiles.id')
            ->where('tabfiles.file',"=",$request->input('namSelNumFile'))
            ->get();

}//pesquisarExecutar

In this method above, how could you make the array $ result be used on the same original page (listar.blade.php), below the form that caused this data collection? p>

The structure of this array $ result could complete the code with the form somehow:

@extends ('PrincipalView')
@corpo
  <form name="frmTSPesquisar" 
action="{{  action('TSController@pesquisarExecutar') }}" method="GET" role="form">
    Busca: <input list="files" placeholder="20000">
    <datalist id="files">
    <option>20000</option>          
    </datalist>         
    <button type="submit">Pesquisar</button>
    </form>
@stop
{{-- abaixo seria o que eu preciso para interagir com a resposta via array --}}
@foreach ($resultado as $r)
{{r$->datalancamento}}
@endforeach

Finally, my problem is, I believe, how to pass the array to the view and, once in this view, how to loop to take advantage of every value obtained inside the array.

    
asked by anonymous 13.05.2016 / 16:21

1 answer

2

To pass variables to the view in laravel 5. * in the return method of your controller use:

  return  view('listar',compact('resultado'));

    ou 

  return  view('listar',get_defined_vars());
    
13.05.2016 / 20:36