Skip to content

Commit 1f57759

Browse files
committed
Change
1 parent 336fdfd commit 1f57759

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

src/Concerns/CrudOperationsTrait.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,10 @@ trait CrudOperationsTrait
1717
*
1818
* @param array<string, mixed> $attributes The record attributes
1919
*/
20-
public function createRecord(array $attributes): ?Model
20+
public function createRecord(array $attributes, mixed $currentColumn): ?Model
2121
{
2222
$model = $this->baseQuery->getModel()->newInstance();
2323

24-
// Apply any scopes from the base query if applicable
25-
// For example, if the base query filters by user_id, we want to set that on the new model
26-
$wheres = $this->baseQuery->getQuery()->wheres;
27-
28-
foreach ($wheres as $where) {
29-
if (isset($where['column']) && isset($where['value']) && $where['type'] === 'Basic') {
30-
// If the filter is a basic where clause, apply it to the new model
31-
// This ensures models created through this adapter respect the base query conditions
32-
$model->{$where['column']} = $where['value'];
33-
}
34-
}
35-
3624
$model->fill($attributes);
3725

3826
if ($model->save()) {

src/Contracts/KanbanAdapterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getEditForm(Form $form): Form;
6969
*
7070
* @param array<string, mixed> $attributes The record attributes
7171
*/
72-
public function createRecord(array $attributes): ?Model;
72+
public function createRecord(array $attributes, mixed $currentColumn): ?Model;
7373

7474
/**
7575
* Update an existing record with the given attributes.

src/Livewire/KanbanBoard.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,13 @@ public function openCreateForm(string $columnId): void
312312
{
313313
$this->currentColumn = $columnId;
314314
$this->recordData = [];
315-
315+
316316
// Set the base model without filling yet
317317
$this->createRecordForm->model($this->adapter->baseQuery->getModel());
318318

319319
// Pre-set the column field
320320
$columnField = $this->config->getColumnField();
321321
$this->recordData[$columnField] = $columnId;
322-
323-
// Apply any order field if needed
324-
$orderField = $this->config->getOrderField();
325-
if ($orderField !== null) {
326-
$count = $this->getColumnItemsCount($columnId);
327-
$this->recordData[$orderField] = $count + 1;
328-
}
329322
}
330323

331324
/**
@@ -352,13 +345,13 @@ public function openEditForm(string|int $recordId, string|int $columnId): void
352345

353346
// Set recordData first
354347
$this->recordData = $record->toArray();
355-
348+
356349
// Clear form state to avoid reactivity issues
357350
$this->editRecordForm->fill([]);
358-
351+
359352
// Set the model on the form - this is crucial for relationships in nested components
360353
$this->editRecordForm->model($record);
361-
354+
362355
// Now fill the form, which will allow nested components to initialize with the model's relationships
363356
// Using the model's data directly instead of recordData to avoid reactivity loops
364357
$this->editRecordForm->fill($record->toArray());
@@ -378,7 +371,7 @@ public function createRecord(): void
378371
$data[$columnField] = $this->currentColumn;
379372
}
380373

381-
$card = $this->adapter->createRecord($data);
374+
$card = $this->adapter->createRecord($data, $this->currentColumn);
382375

383376
if ($card) {
384377
$this->refreshBoard();
@@ -407,7 +400,7 @@ private function resetCreateForm(): void
407400
{
408401
$this->recordData = [];
409402
$this->currentColumn = null;
410-
403+
411404
// Just clear the form without chaining methods
412405
$this->createRecordForm->fill([]);
413406
}
@@ -459,7 +452,7 @@ public function resetEditForm(): void
459452
{
460453
$this->recordData = [];
461454
$this->currentRecord = null;
462-
455+
463456
// Just clear the form without chaining methods
464457
$this->editRecordForm->fill([]);
465458
}

0 commit comments

Comments
 (0)