where($builder->getModel()->getTable() . '.company_id', company_id()); } }); static::creating(function (self $model) { if (empty($model->company_id)) { $model->company_id = company_id(); } }); } /** * Ordered columns (id, then declared columns, then timestamps). * Used by the Blade views to render the table headers and form fields. */ public static function declaredColumns(): array { static $cache = []; $key = static::class; if (isset($cache[$key])) { return $cache[$key]; } /** @var \Illuminate\Database\Schema\SQLiteBuilder $schema */ $schema = (new static())->getConnection()->getSchemaBuilder(); $columns = $schema->getColumnListing((new static())->getTable()); // Re-order: primary key first, then declared columns, then timestamps. $ordered = array_values(array_filter($columns, function (string $col) { return ! in_array($col, ['id', 'company_id', 'created_at', 'updated_at'], true); })); return $cache[$key] = ['id' => 'id'] + array_combine($ordered, $ordered); } /** * Column human-readable labels (overridable per model). */ public static function columnLabels(): array { return []; } }