Whitney W.
Whitney W.

Reputation: 85

How to retrieve data fields in a table for a drop down menu in Laravel 5.2

I hope I can get assistance from here. A very amateur to Laravel.

Here is my code. I am trying to create a drop down select menu and the data should be from the database from another table which is actually connected using a foreign key only.

         <div class="form-group">
         {{ Form::select('size', array('a' => '', 'b' => ''), null,array('class'=>'form-control','style'=>'','placeholder' => 'Select Activity   Category:','required' )) }}</div>


         public function createPackage()
{
    $package = chap_activity_package::all();
    return view ('Chap_activity_packages.chap_activity_package',  compact('chap_activity_packages'));
}

Upvotes: 2

Views: 401

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

You should use pluck() method which will generate list of properties for you, like:

$data = chap_activity_package::pluck('name', 'id');

Then use this data in Form::select:

{!! Form::select('size', $data, null, array('class'=>'form-control', 'style' => '', 'placeholder' => 'Select Activity Category:', 'required' )) !!}

Upvotes: 2

Related Questions