Simple search engine with laravel

0

I want to do a simple search with pagination, and to show the result below the search button, the most I have arrived is to show the arrangement with the information in the database, the question is: How do I show the information? by pressing the search button, for example if I want to search only the program_program column of the database, so that the results are displayed below.

1.-View

@extends('layouts.default')
@section('content')

    <div class="panel panel-success">
            <div class="panel-heading">buscar Noticiero</div>
            <form action="noticia/buscar" method="get" onsubmit="return showLoad()">
            <div class="panel-body">
                <label class="label-control">Nombre del noticiero</label>
                <input type="text" name="noticiero_turno" class="form-control" placeholder="Ingresar nombre del noticiero/descripcion" required="required">
                <br>

        </div>
        <div class="panel-footer">
            <button type="submit" class="btn btn-success">buscar</button>
        </div>
        </form>
    </div>

    <!-- check if $buscar variable is set, display buscar result -->
    @if (isset($buscar))
        <div class="panel panel-success">
            <div class="panel-heading">Resultado de la busqueda</div>
            <div class="panel-body">

                <div class='table-responsive'>
                  <table class='table table-bordered table-hover'>
                    <thead>
                      <tr>
                        <th>ID</th>
                        <th>PROGRAMA</th>
                        <th>TURNO</th>
                        <th>FECHA</th>

                      </tr>
                    </thead>
                    <tbody>

                    @foreach($buscar as $buscars)
                        <tr>
                            <td>{{$buscars->id}}</td>
                            <td>{{$buscars['noticiero_programa']}}</td>
                            <td>{{$buscars['noticiero_turno']}}</td>
                            <td>{{$buscars['noticiero_fecha']}}</td>
                        </tr>
                    @endforeach

                    </tbody>
                        </table>
                        <center>{{ $buscar->appends(Request::only('noticiero_turno','noticiero_programa'))->links() }}</center>
                    </div>

            </div>
            <div class="panel-footer">
                <a href="{{url('noticia/buscar')}}" class="btn btn-warning">Restaurar busqueda</a>
            </div>
        </div>
    @endif

    @stop

2.-Controller

public function busqueda(Request $request)
{
    $input = $request->all();

    if($request->get('busqueda')){
        $noticias = Noticia::where("noticiero_turno", "LIKE", "%{$request->get('busqueda')}%")
            ->paginate(5);
    }else{
  $noticias = Noticia::paginate(5);
    }

    return response($noticias);
}

3.-Routes

 Route::get('noticia/buscar', 'NoticiaController@busqueda');

Fix

4.-News table database

    
asked by CARLOS OMAR BLANCO RODRÍGUEZ 21.03.2018 в 04:19
source

1 answer

2

You are not sending the variable $buscar to the view, so we do not list the results.

public function busqueda(Request $request)
{
    $input = $request->all();

    if($request->get('busqueda')){
        $noticias = Noticia::where("noticiero_turno", "LIKE", "%{$request->get('busqueda')}%")
            ->paginate(5);
      return view('NOMBRE_VISTA')->with('buscar', $noticias);
    }
    //else{
    //  $noticias = Noticia::paginate(5);
    //}

    // return response($noticias);
    return view('NOMBRE_VISTA');
}

I hope I have been helpful, Regards

    
answered by 26.03.2018 / 08:06
source