Join in laravel

2

I have my in my controller:

$habitaciones = DB::table('habitaciones')
        ->join('tipo_habitaciones', 'habitaciones.id_tipo', '=', 'tipo_habitaciones.id')
        ->select('habitaciones.*', 'habitaciones.id', 'habitaciones.hab_numero', 'habitaciones.hab_num_camas','habitaciones.hab_estatus','habitaciones.hab_costo', 'tipo_habitaciones.tip_nombre','habitaciones.hab_urlimg')
        ->get();  return view('admin.habitacion_listar', compact('habitaciones'));

and my eyesight

    @extends('layout.menu')

          @section('content')
     <div class="container">
     <center><a href="{{url('/habitacion/create')}}" class="btn btn-default">           
     Registrar habitación</a></center>
     <table class="table table-striped  table-bordered">
        <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel-body">        
                <thead>
                    <th style="visibility:hidden">ID</th>
                    <th>Número de habitación</th>
                    <th>Número de camas</th>
                    <th>Estatus</th>
                    <th>Costo</th>
                    <th>tipo de habitación</th>
                    <th>Imagen</th>
                    <th>Acciones</th>
                </thead>
                <tbody>

                    @foreach ($habitaciones as $hab)

                    <tr class="table-default "> 
                        <td style="visibility:hidden" >{{$hab->id}}</td>
                        <td>{{$hab->hab_numero}}</td>
                        <td>{{$hab->hab_num_camas}}</td>

                        @if ($hab->hab_estatus === 1)<td>{{'Ocupada'}}</td>@else<td>{{'Desocupada'}}</td>
                        @endif

                        <td>{{$hab->hab_costo}}</td>
                        <td>{{$hab->tip_nombre}}</td> 
                        <td>{{$hab->hab_urlimg}}</td>
                        <td>
                               <a href="{{route('reservacion.create', $hab->id)}}" class="btn btn-info"><span class="glyphicon glyphicon-calendar"></span></a>

                              <a href="{{route('habitacion.editar', $hab)}}" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a> 

                            <a href="{{route('habitacion.eliminar', $hab->id)}}"  onclick="return confirm('¿Seguro que deseas eliminarlo?')" class="btn btn-danger btn-sm">
                            <span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
                            </td>
                    </tr>
                    @endforeach
                </tbody>
            </div> 

        </div> 
    </div>

</table>

</div>
<div class="text-center">
</div>
   <footer>
            @include('layout.footer')
        @yield('')
  </footer>
   @endsection

and send me this error:

  

ErrorException in UrlGenerator.php line 377:

     

Object of class stdClass could not be converted to string (View: /Library/WebServer/Documents/hotel/resources/views/admin/habitacion_listar.blade.php)

    
asked by Estefania 01.03.2018 в 23:52
source

1 answer

3

On the next line you are passing an object instead of the id:

<a href="{{route('habitacion.editar', $hab)}}" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>

It should be:

{{route('habitacion.editar', $hab->id)}}
    
answered by 02.03.2018 / 00:13
source