Reputation: 12082
This can be so simple but I'm almost burnt out and my brain is blanked. I have added a column to the users table along with others: country
. In my User Model I have the protected fillable set for country
and along with the others.
My form is like this:
<div class="form-group">
{!! Form::label('country', 'Country') !!}
{!! Form::select('country', ['USA', 'UK'], ['class' => 'form-control']) !!}
</div>
Before I go nuts, because the other columns Ive added to the users table worked so am I going mad? Should I call it a day and clearly that should work. Please help.
The controller:
public function update(@company_name)
{
$user = User::whereCompanyName($company_name)->firstOrFail();
$user->fill(Input::all());
$user->save();
flash('You have successfully edited your profile');
return redirect('/');
}
In my migration:
$table->string('country')->unique()->nullable();
Upvotes: 0
Views: 1083
Reputation: 2817
the third argument to the Form::select() call should be the default value to the select field:
{{ Form::select('country', ['usa' => 'USA', Input::old('country') => 'UK'], 'uk', ['class' => 'form-control']) }}
the second argument is an associated array with the keys (first entry) indicating the value attributes of the option elements and the second entries the text to display. The third argument takes the first entry (or the key in the associative array) of the item you want to default to.
If you want the Input::old('country') to show your previous selection when it comes back, you need to change your controller's return statement to:
return Redirect::to('/')->withInput()
Upvotes: 1