0

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>
Derek Pollard
  • 6,953
  • 6
  • 39
  • 59
Rain
  • 7
  • 1
  • 1
  • 4

1 Answers1

0

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']) }}
nakov
  • 13,938
  • 12
  • 60
  • 110
  • now I get: Integrity constraint violation: 1048 Column 'level' cannot be null (23000) – Rain Apr 16 '19 at 08:23
  • Do you have a default selection? The problem is because you are not setting the `level` to any value. Debug your `$request->input('level')` does it returns anything? Make sure that you have `level` in your `$fillable` array of your model. – nakov Apr 16 '19 at 08:38
  • Integrity error was because of my typo in Controller file, so the main issue is solved, thanks. I do not have an array in my model, please write in code what you mean, you see I am a beginner... – Rain Apr 16 '19 at 08:55
  • If it works than that's great. I was talking about the mass asignment part, you can read more about it in the docs [here](https://laravel.com/docs/master/eloquent#mass-assignment). – nakov Apr 16 '19 at 09:00