Table does not edit the correct item
I have a relation manager, who manages the pivot:
Schema::create('country_license', function (Blueprint $table) {
$table->unsignedSmallInteger('license_id');
$table->foreign('license_id')->references('id')->on('licenses')->onUpdate('cascade');
$table->unsignedTinyInteger('country_id');
$table->foreign('country_id')->references('id')->on('countries')->onUpdate('cascade');
$table->string('region')->default('All');
$table->primary(['license_id', 'country_id', 'region']);
});
In the table:
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('region'),
])
And the form:
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('recordId')
->label('Country')
->options([list of countries])
->searchable()
->required(),
Forms\Components\TextInput::make('region')
->placeholder('Example: Ontario')
->required()
->default('All'),
]);
}
The problem is that when there are two countries, with different regions, and I click to edit one of them, it always edits the first one. It is not choosing the row to edit. How can I do it?2 Replies
Solution
add
$table->id()
in the pivot tableI tried, by it didn't work. Anyway, I'll do it with a json field, keeping it simple. Thanks