Created
January 12, 2016 15:02
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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