How to make a filer in laravel 5.3

0
Hello, I have tried to make a form that receives a cpf and if this cpf is in the database it returns all the data linked to that cpf (name, title, code etc) just next to the form, in the same view. But I'm having a hard time doing it. Here are the codes:

Controller:

class SolicitanteController extends Controller
{   
    #Tela de Inicio
    public  function inicio(){

        $resultado = Servidor::all();
        return view('usuarios/solicitantes/inicio');

    }

    public function pegarServidor(Request $request){

        $resultado = Servidor::all();
        if($request->has('cpf')){

            $resultado = $request->get('cpf');

            return view('usuarios/solicitantes/inicio', ['resultado' => $resultado]);
        }


        return Redirect::to('usuarios/solicitantes/historico');

    }

View:

@extends('layouts.app')

@section('content')

    @if(Session::has("msg_sucesso"))
                            <div class="alert alert-success"> {{ Session::get('msg_sucesso')}} </div>
                        @endif

    <div class="container">
        <div class="container">
            <div class="row">
                <div class="col-md-4">
                    <section id="secao_servidor">
                        {!! Form::open(['method'=>'GET', 'url' => 'usuarios/solicitantes/pegarServidor']) !!}

                            {!! Form::label('cpf', 'CPF: ') !!}
                            {!! Form::input('text', 'cpf', null, ['class' => 'form-control', 'autofocus']) !!}
                            <br>
                            {!! Form::submit('Confirmar', ['class' => 'btn btn-primary']) !!}

                        {!! Form::close() !!}
                    </section>  
                </div>
                <div class="col-md-8">
                    <section id="secao_dadosServidor">
                        {!! Form::model('$resultado', ['method'=>'PATH', 'url' => 'usuarios/solicitantes/adicionarServidor]) !!}
                        <div class="col-md-4">
                            <ul>

                                <li>{!! Form::input('text', 'nome',$resultado->nome, ['class' => 'form-control', 'autofocus']) !!} </li>

                                <li>Função: </li>
                                <li>Nº Banco:</li>
                            </ul>
                        </div>
                        <div class="col-md-4">
                            <ul>
                                <li>Cargo: </li>
                                <li>Beneficiario: </li>
                                <li>Agência: </li>
                                <li>Conta: </li>
                            </ul>
                        </div>
                        <div>
                        {!! Form::close() !!}
                        </div>

                    </section>
                </div>
                </div>
            </div>
        </div>
    </div>  

Here in the view I made two form, one for each to get the cpf and another to display the fields. I just put an input to test. I want to automatically load the data into inputs because I'm going to reuse them.

    
asked by anonymous 03.11.2016 / 20:19

0 answers