You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using your package, when I first time edit it assigns correctly the role, but when I return again to edit page, and click again Save button I get this error:
Forms\Components\Select::make('roles')
->relationship(name: 'roles', titleAttribute: 'name')
->saveRelationshipsUsing(function ($record, $state, $get) {
$record->roles()->syncWithPivotValues($state, [config('permission.column_names.team_foreign_key') => 1]); // I'm hardcoding the team id for now
})
->multiple()
->preload()
->searchable()```
Any idea what I'm doing wrong?
This is the migration code from spatie permissions for mode_has_roles:
```php
Schema::create($tableNames['model_has_roles'], function (Blueprint$table) use ($tableNames, $columnNames, $pivotRole, $teams) {
$table->unsignedBigInteger($pivotRole);
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
$table->foreign($pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->onDelete('cascade');
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');
$table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
} else {
$table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
}
});`
The text was updated successfully, but these errors were encountered:
Hello,
I'm using your package, when I first time edit it assigns correctly the role, but when I return again to edit page, and click again Save button I get this error:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-1-236-App\Models\User' for key 'PRIMARY' (Connection: mysql, SQL: insert into
model_has_roles(
model_id,
model_type,
role_id,
team_id`) values (236, App\Models\User, 1, 1))`
This is the code I use:
The text was updated successfully, but these errors were encountered: