Skip to content

Commit 850e70a

Browse files
committed
Fix: BadMethodCallException for getDeletedAtColumn() on models without SoftDeletes
Issue: shouldQualifyColumn() method was unconditionally calling getDeletedAtColumn() which only exists on models using the SoftDeletes trait. This caused a fatal error when querying models like Permission that don't use soft deletes. Error: BadMethodCallException: Call to undefined method Fleetbase\Models\Permission::getDeletedAtColumn() Fix: Check if the method exists before calling it using method_exists(). Only include deleted_at column in qualifiable columns if the model uses SoftDeletes. Impact: - Fixes fatal error when querying Permission and other non-soft-deletable models - Maintains backward compatibility with models that do use SoftDeletes - No functional changes to soft-delete behavior
1 parent 42a2335 commit 850e70a

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/Traits/HasApiModelBehavior.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,12 +1125,18 @@ private function applyOperators($builder, $column_name, $op_key, $op_type, $valu
11251125
*/
11261126
public function shouldQualifyColumn($column_name)
11271127
{
1128-
return in_array($column_name, [
1128+
$qualifiableColumns = [
11291129
$this->getKey() ?? 'uuid',
11301130
$this->getCreatedAtColumn() ?? 'created_at',
11311131
$this->getUpdatedAtColumn() ?? 'updated_at',
1132-
$this->getDeletedAtColumn() ?? 'deleted_at',
1133-
]);
1132+
];
1133+
1134+
// Only include deleted_at column if model uses SoftDeletes trait
1135+
if (method_exists($this, 'getDeletedAtColumn')) {
1136+
$qualifiableColumns[] = $this->getDeletedAtColumn();
1137+
}
1138+
1139+
return in_array($column_name, $qualifiableColumns);
11341140
}
11351141

11361142
/**

0 commit comments

Comments
 (0)