2

Tengo mi en mi controlador:

$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'));

y mi vista

    @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

y me manda este 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)

1 respuesta 1

3

En la siguiente línea estás pasando un objeto en vez del id:

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

Debería ser:

{{route('habitacion.editar', $hab->id)}}
1
  • Muchas gracias por tu ayuda, efectivamente era por que estaba pasándole el objeto.
    – Estefania
    el 1 mar. 2018 a las 23:20

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.