Skip to content

Instantly share code, notes, and snippets.

@permatis
Created January 12, 2016 15:02
Show Gist options
  • Save permatis/8580df33157ccc6d90f7 to your computer and use it in GitHub Desktop.
Save permatis/8580df33157ccc6d90f7 to your computer and use it in GitHub Desktop.
How to resolve problem about many to many relation with 'sync' function in laravel 5.
<?php
//Problem 1 : Argument 1 passed to Illuminate\Database\Eloquent\Relations\BelongsToMany::formatSyncList() must be of the type array, null given, called
$tabelA->tabelB()->sync($request->get('col1'), $request->get('col2'));
//Problem 2 : Integrity constraint violation: 1048 Column 'col2_id' cannot be null
$tabelA->tabelB()->sync([$request->get('col1'), $request->get('col2')]);
//How to resolve
$data = array_slice($request->all(), 1); //remove _token post data
$table->tableB()->sync([$data]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment