php - Laravel creating a form select with default value set -


controller:

$employee = staff::where('staff_id', '=', $id)->where('user_role', '=','employee')->first(); $emp_loc = $employee->locations()->pivot()->only('loc_id'); $locations_list = location::lists('address1', 'loc_id'); //get list of locations 

view:

<!--location --> <div class="control-group"> <label class="control-label">location</label> <div class="controls"> @if(isset($emp_loc)) {{ form::select('location', $locations_list, $emp_loc) }} @else {{ form::select('location', $locations_list) }} @endif </div> </div> 

the third parameter meant default value select box begins @ first value.

source code:

<div class="control-group"> <label class="control-label">location</label> <div class="controls"> <select name="location"><option value="1">bethel</option><option value="2">brooklyn</option><option value="3">germantown</option><option value="4">memphis</option><option value="5">brooklyn</option></select>        </div> </div> 

no default value set?

it might database configuration problem.

go migration file , make sure foreign keys set properly. set them:

schema::create('pivot', function(blueprint $table) {   $table->increments('id');   $table->unsignedinteger('loc_id');   $table->foreign('loc_id')    ->references('id')->on('location_list');   ..... }  schema::create('location_list', function(blueprint $table) {   $table->increments('id');   ..... } 

moreover, pay attention in firefox selected value not displayed properly. fix this, change drop-down list (in blade):

form::select('location', $locations_list, $emp_loc, array('autocomplete'=>'off'))

this last part weird behavior of firefox


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -