Object of class stdClass could not be converted to string

0

From the controller I execute the following query:

    $pruebas = DB::select( DB::raw("SELECT 
    t1.id,
    t2.name AS 'Type',
    t4.company AS 'Company',
    t4.name AS 'clientName',
    t4.lastname AS 'clientLastName',
    t4.email AS 'Contact',
    t3.name AS 'Status',
    t1.created_at,
    t1.'when' FROM quotation t1
    JOIN quotation_type t2 ON t1.id_quotation_type = t2.id
    jOIN quotation_status_type t3 ON t1.id_quotation_status_type = t3.id
    JOIN client t4 ON t1.id_client = t4.id") );

    return view('home')->with("pruebas", $pruebas);

I want to load the data obtained in a table but I get the following error:

  

Object of class stdClass could not be converted to string (View: /Users/Hernan/Desktop/BRAVALL/project/resources/views/home.blade.php)

In the html it is by default the table and I do not understand what the problem is, please help:

                    @if(count($pruebas) > 0)
                <table class="table table-bordered table-hover" id="myTable">

                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Tipo</th>
                            <th>Empresa</th>
                            <th>Cliente</th>
                            <th>Contacto</th>
                            <th>Estado</th>
                            <th>Fechaa</th>
                            <th>Fechab</th>
                        </tr>
                    </thead>
                    <tbody>
                        @if (count($pruebas)) @foreach ($pruebas as $prueba)
                        <tr>
                            <td><a href="/quotedetail?data=<?echo urlencode("$prueba");?>">#{{ $prueba->id }}</a></td>
                            <!-- <td><a href="/provider?data={{$prueba}}">#{{ $prueba->id }}</a></td> -->
                            <td>{{ $prueba->Type }}</td>
                            <td>{{ $prueba->Company }}</td>
                            <td>{{ $prueba->Client }}</td>
                            <td>{{ $prueba->Contact }}</td>
                            <td>{{ $prueba->Status }}</td>
                            <td>{{ $prueba->created_at }}</td>
                            <td>{{ $prueba->when }}</td>
                        </tr>

                        @endforeach @else
                        <h1>No hay registros</h1>
                        @endif
                    </tbody>
                </table>
                @else
                <div class="alert alert-danger">
                    No se encontrarón registros
                </div>
                @endif

The returning array is as follows:

    
asked by Hernan Humaña 16.03.2018 в 17:20
source

2 answers

2

The problem is due to the line:

 <!-- <td><a href="/provider?data={{$prueba}}">#{{ $prueba->id }}</a></td> -->

Since although commented on the line where you print with blade the variable $ test equal to the template engine laravel blade will interpret it as a php variable and being an array and not a string you get the error.

    
answered by 16.03.2018 в 17:41
0

In the links you are passing the object and not the value you need to complete the url, it is probably the id or a slug:

<td><a href="/quotedetail?data={{urlencode("$prueba->id")}}>">#{{ $prueba->id }}</a></td>
<!-- <td><a href="/provider?data={{$prueba->id}}">#{{ $prueba->id }}</a></td> -->
    
answered by 16.03.2018 в 17:31