雄辩的查询从另一个表中检索数据

时间:2020-09-03 21:13:52

标签: laravel eloquent

我是Laravel的新朋友。我想通过口才查询来检索此数据。由于某种原因,它从具有相同行名的另一个表中检索数据,这是代码:

@extends('panel')
@section('contenido')

    <div class = 'container'>
        <form action="{{url('panelNewPolizasNew/search')}}" class="form-inline">
            <div class="input-group mb-2 mr-sm-2">
                <input type="text" class="form-control" placeholder="Buscar Pólizas" name="buscadorpolizas">
            </div>
            <button type="submit" class="botones btn btn-primary btn mb-2"><i class="fa fa-search"></i></button>
        </form>
        <br>


        <nav>
            <ul class="form-inline" style="padding-left: 0px">
                <li class="input-group mb-2 mr-sm-2 botones btn btn-primary btn mb-2 ">
                    <a href="{{route('moderatednewpolicy')}}">Moderadas<i></i></a>
                </li>
                <li class="input-group mb-2 mr-sm-2 botones btn btn-primary btn mb-2">
                    <a href="{{route('unmoderatednewpolicy')}}">Sin Moderar<i></i></a>
                </li>
                <li class="input-group mb-2 mr-sm-2 botones btn btn-primary btn mb-2">
                    <a href="{{route('allnewpolicies')}}">Todas<i></i></a>
                </li>
            </ul>

        </nav>

        <div id='tablePolicies'>
            <table class="table margin-15">
                <thead class="thead-dark">
                <tr>
                    <th>#</th>
                    <th>Tipo de póliza</th>
                    <th>Valor</th>
                    <th>Monto</th>
                    <th>Ciudad</th>
                    <th>Cliente</th>
                    <th>Estado</th>
                    <th class="text-center">Acciones</th>
                    <th>
                </tr>
                </thead>
                <tbody>
                @if (isset($poliza))
                    @php $i=1
                    @endphp
                    @foreach ($poliza as $polizas)
                        <tr>
                            <th scope="row">{{$polizas->id}}</th>
                            <td>{{$polizas->type}}</td>
                            <td>{{'$'.$polizas->value}}</td>
                            <td>{{'$'.$polizas->amount}}</td>
                            <td>{{$polizas->city}}</td>
                            <td>{{$polizas->client->name}}{{" ".$polizas->client->last_name}}</td>
                            @if ($polizas->moderate === 0)
                                <td class="text-left"><i class="fa fa-times-circle fa-2x text-danger" title="Bloqueado"></i></td>
                                <td class="text-center"><a href="{{route('approvepolicy',$polizas->id)}}" onclick="return confirm('Aprobar la poliza?')" class="btn btn-primary btn-sm"><i class="fas fa-thumbs-up fa-fw" title="Aprobar"></i></a>
                            @else
                                <td class="text-left"><i class="fa fa-check-circle fa-2x text-success" title="Activado"></i></td>
                                <td class="text-center"><a href="{{route('approvepolicy',$polizas->id)}}" onclick="return confirm('Aprobar la poliza?')" class="btn btn-primary btn-sm"><i class="fas fa-thumbs-down fa-fw" title="Aprobar"></i></a>

                            @endif

                                <a href="{{route('deletepolicy',$polizas->id)}}" onclick="return confirm('Eliminar la poliza?')" class="btn btn-danger btn-sm""><i class="fa fa-trash fa-fw" title="Eliminar"></i></a>
                                <a href="{{route('editpolicy',$polizas->id)}}" class="btn btn-success btn-sm"><i class="fas fa-info fa-fw" title="Ver detalles"></i></a></td>
                            <td class="text-center"></td>





                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            {{$poliza->links()}}
        </div>
    </div>
    </div>

@endsection
     public function searchn(Request $request) {

        $filtrado = $request->input('buscadorpolizas');
        $palabras = explode (' ',$filtrado);

        $poliza = Policy::join('users','policies.client_id','=','users.id')
            ->where(function($query) use ($palabras) {
                $query->where(function($query) use ($palabras) {
                    foreach ($palabras as $palabra) {
                        $query->orWhere('policies.postal_code','like', "%{$palabra}%");
                    }
                })->orWhere(function($query) use ($palabras) {
                    foreach ($palabras as $palabra) {
                        $query->orWhere('policies.city','like', "%{$palabra}%");
                    }
                })->orWhere(function($query) use ($palabras) {
                    foreach ($palabras as $palabra) {
                        $query->orWhere('policies.observations','like', "%{$palabra}%");
                    }
                })->orWhere(function($query) use ($palabras) {
                    foreach ($palabras as $palabra) {
                        $query->orWhere('policies.car_motorcycle_brand','like', "%{$palabra}%");
                    }
                })->orWhere(function($query) use ($palabras) {
                    foreach ($palabras as $palabra) {
                        $query->orWhere('policies.car_motorcycle_model','like', "%{$palabra}%");
                    }
                })->orWhere(function($query) use ($palabras) {
                    foreach ($palabras as $palabra) {
                        $query->orWhere('policies.car_motorcycle_year',  "%{$palabra}%");
                    }
                })->orWhere(function($query) use ($palabras) {
                    foreach ($palabras as $palabra) {
                        $query->orWhere('policies.car_motorcycle_version',  "%{$palabra}%");
                    }
                })->orWhere(function($query) use ($palabras) {
                    foreach ($palabras as $palabra) {
                        $query->orWhere('users.name',  "%{$palabra}%");
                    }
                })->orWhere(function($query) use ($palabras) {
                    foreach ($palabras as $palabra) {
                        $query->orWhere('users.last_name',  "%{$palabra}%");
                    }
                })->orWhere(function($query) use ($palabras) {
                    foreach ($palabras as $palabra) {
                        $query->orWhere('policies.covered_surface',  "%{$palabra}%");
                    }
                });
            })->whereNotNull('producer_id')->paginate(15);
        return view('panelNewPolizasNew',compact('poliza'));

您可以看到$ polizas-> value是正确的,$ polizas-> amount,value city和用户名也是正确的,但是“ type”是错误的。它检索用户类型,而不是策略类型。我想念的是什么?

谢谢!

0 个答案:

没有答案