hi i need to insert an array in a table and i don't know how to do i'm using the select2 plugin to select multiple values as tags and insert them in database as an array the input looks like this
<select name="designation[]" class="form-control" multiple="multiple" id="select2"></select>
//script
$('#select2').select2({
tags: true,
tokenSeparators: [',', ' '],
selectOnClose: true
});
EventController
public function store(Request $request){
$validator = $request->validate([
'theme' => ['required','unique:events,theme'],
]);
$event = Event::create($request->except('designation'));
$event->montant()->insert($request->get('designation'));
return redirect()->to(route('admin.event.index'))
->withFlashSuccess('L\'éventment a bien etait ajouté');
}
with this code when i submit the form i have this error
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into event_montants (0, 1) values (222, 111))
event_montant migration
public function up()
{
Schema::create('event_montants', function (Blueprint $table) {
$table->increments('id');
$table->bigInteger('designation');
$table->unsignedInteger('event_id');
$table->foreign('event_id')->references('id')->on('events')
->onDelete('cascade');
$table->timestamps();
});
}
please help i need to resolve this
insertis expecting an associative array where the keys are the field names, you are passing a zero-indexed array so it thinks your fields are named 0 and 1 ... not sure what field you are trying to save or why you would be trying to put an array in a single field