getProperty('table'); $table_prop->setAccessible(true); $instance = $reflection->newInstanceWithoutConstructor(); $table_name = $table_prop->getValue($instance); // Get the $enums property if it exists if (!$reflection->hasProperty('enums')) { return; } $enums_prop = $reflection->getProperty('enums'); $enums_prop->setAccessible(true); $enums = $enums_prop->getValue(); if (!is_array($enums)) { return; } // Get table columns from database $columns = Schema::getColumnListing($table_name); // Check each enum field $lines = explode("\n", $contents); foreach ($enums as $column => $definitions) { if (!in_array($column, $columns)) { // Find the line where this enum is defined $line_number = 1; foreach ($lines as $i => $line) { if (preg_match('/[\'"]' . preg_quote($column) . '[\'"\s]*=>/', $line)) { $line_number = $i + 1; break; } } $this->add_violation( $file_path, $line_number, "Enum field '{$column}' does not exist as a column in table '{$table_name}' (Have migrations been run yet?)", $lines[$line_number - 1] ?? '', "Remove the enum definition for '{$column}' or add the column to the database table", 'high' ); } } } catch (Exception $e) { // If we can't check the database schema (e.g., during CI or before migrations), // skip this validation return; } } }