Sunday, March 5, 2017

Displaying form elements obtained from database

I have a questions table which has a variety of questions of different input types. The format in my seeder is like so

 DB::table('questions')->insert([
            'name' => 'name',
            'type' => 'text',
            'text' => 'Name',
]);

DB::table('questions')->insert([
            'name' => 'title',
            'type' => 'select',
            'text' => 'Title',
            'values' => serialize(['Mr', 'Mrs', 'Ms']),
            'class' => 'selectpicker'
]);

So you can see the above I have one text input and one select, which has serialized list of values. Now within my controller I get the Questions and pass it to my view.

Within my view, I am doing something like the following

@foreach($questions as $q)
    <div class="col-xs-12">
        <input type="" 
                class="form-control "
                id="" 
                name="questions[]"
        >
    </div>
@endforeach

Where I am having difficulty is with the select inputs. How would I go about displaying my selects along with their options (values)?

Thanks



via kate_hudson

Advertisement