I am using livewire with Laravel 8 for insertion of a form into my database and I am getting the following error. i tried json encode on the grade variable but i am unable to resolve the issue.
//my insertion view
<div >
<select class="form-control" id="select2-dropdown">
<option value="">Select Option</option>
<option value="{{ $item }}">{{ $item }}</option>
@foreach($grade as $item)
<option value="{{ $item }}">{{ $item }}</option>
@endforeach
</select>
</div>
//inside livewire/wizard
class Wizard extends Component
{
public $currentStep = 1;
public $first_name, $price, $detail,$middle_name,
public $grade = [
'one',
'two',
'Three',
'Four'
];
public function submitForm()
{
Student::create([
'grade' =>$this->grade
]);
in the blade
<select class="form-control" id="select2-dropdown" wire:model="selectedItem"> // wire:model bind to the property
<option value="">Select Option</option>
@foreach($grade as $item)
<option value="{{ $item }}">{{ $item }}</option>
@endforeach
</select>
in component
public $selectedItem;
public $grade = [
'one',
'two',
'Three',
'Four'
];
public function submitForm()
{
Student::create([
'grade' =>$this->selectedItem
]);
}