php - Laravel model is created with id = 0 -


i having problem eloquent. here's code:

$basetask = $taskclass::create([         'user_id' => $user->id,         'task_type' => $this->task_type,         'name' => $this->settings['name'],         'task_' . $this->social_network . '_list_id' => $task_list_id, ]); $basetask->accounts()->attach($account_id); 

the problem sometimes last line fails foreign key constraint fails - tries update pivot table query

insert pivot ('account_id', 'task_id') values (289530, 0)) 

so somehow:

$basetask->id=0; 

but have property:

$incrementing=true; 

maybe faced such issue, appreciated!

use save() method instead, since don't have many many relationship. if have many many use sync() function then. go database.php file set mysqlstrict false


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -