Thursday, March 2, 2017

Getting array keys instead of the value with laravel

Hello everyone im getting a problem while i want to loop throug an array and display it with laravel blade engine

My controllers code is like this

    $table =  DB::table('tables')->select('id')->where('name', strtolower($name))->first();

    $columns =  Column::where('table_id', $table->id)->get();

    foreach ($columns as $col) {
        $data[] = $col->col_name;
    };

    $content = DB::table($name)->select(...$data)->get();


    return view('back.group.view-table', compact('content', 'columns', 'data'));

And my blade view code is like this

<table class="table table-striped">
            <thead>
                <tr>
                    @foreach($columns as $column)
                        <th></th>
                    @endforeach
                </tr>
            </thead>
            <tbody>
                @foreach ($content as  $value)
                    <tr>

                        @for ($i = 0; $i < count($columns); $i++)
                            <td></td>
                        @endfor

                    </tr>
                @endforeach

            </tbody>
        </table>

This is the result wich i get with the following code

The result i want to have




via Eth0

Advertisement