Oct 2, 2019
0
Level 18
Unexpected error with sync method in test environment
Laravel 5.8.34
we have 3 tables, roles, permissions and the pivot table role_permission that does not have an ID
this line of code works well in the browser
// Role.php
$this->permissions()->sync($permission);
but in my test environment I get this error where he tries to put the permissions fields in my pivot table
Unknown column 'id' in 'field list' (SQL: insert into `role_permission` (`created_at`, `id`, `label`, `name`, `permission_id`, `role_id`, `updated_at`) values (?, 2, ?, cadastrar_pessoa, 0, 1, ?))
id, label and name are from the permissions table
My test database is mysql as well my dev
A way around
I can solve that error in test doing this
// Role.php
$permission = Permission::select('id as permission_id')->whereIn('name', $permission)->get();
return $this->permissions()->sync($permission);
but I don't want to do this in all my tests
Please or to participate in this conversation.