vendredi 7 octobre 2016

laravel & Blade Dynamically load collumn names from table

I'm trying to populate my user profile forms and since the database table has a lot of collumns I'm trying to see if it's possible to load them automatically.

I sort of have it working. But at the moment it prints out a list of numbers (the table collumn ID I assume), rather than the names of the collumns.

What am I missing?

This is the blade file:

@extends('layout')


@section('content')
    <h1>User Profile Data</h1>

        @foreach ($columns as $collumn => $name)
            

        @endforeach

            @foreach ($profile as $person)
                @foreach ($person as $name)
                    <br>
                @endforeach
            @endforeach

@stop

This is the controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;

class UserEntryController extends Controller
{
   public function index(){
       $columns = DB::getSchemaBuilder()->getColumnListing('users');
       $profile = DB::table('users')->where('ID', '682')->get();
       return view('UserEntry', compact('profile', 'columns'));
   }


}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire