Search code examples
laravellaravelcollective

Laravel Collective drop-down to mysql in Laravel 5.8


I get the error:

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'level'..

My guess is that Form::select should be used somehow differently, how?

// in my migration:
$table->enum('level', ['easy', 'hard']);

// in my controller Store function:
$tablee = new Tablee; // this is view file called Tablee.php
$tablee->level = $request->input('level');
$tablee->save();

// and part of my code in create.blade.php
<div class="form-group">
  {{Form::label('level', 'Please choose level')}}
  {{Form::select('level', ['easy' => 'easy', 'hard' => 'hard'], ['class' => 'form-control'])}}
</div>

Solution

  • The third argument of Form::select is the selected element.

    public function select($name, $list = [], $selected = null, $options = [])
    

    So you should change yours to be

    {{ Form::select('level', ['easy' => 'easy', 'hard' => 'hard'], null, ['class' => 'form-control']) }}