When dealing with column names that start with a number, you're right that PHP variables cannot start with a number. However, Eloquent can still work with these column names directly when interacting with the database. The issue arises when you want to document these columns using PHPDoc @property annotations, as PHPDoc follows the same variable naming rules as PHP.
To document a property that corresponds to a column starting with a number, you can use a variable name that starts with an underscore followed by the number, as you suggested. This won't affect Eloquent's functionality but will provide a valid PHPDoc annotation.
Here's how you can define the @property annotation for the 4wd column:
/**
* @property ?string $_4wd Corresponds to database column '4wd'
*/
class YourModel extends Model
{
// Model methods and properties
}
When accessing the 4wd column in your Eloquent model, you would still use the actual column name:
$model = YourModel::find($id);
$value = $model->{'4wd'}; // Accessing the '4wd' column
Remember that the @property annotation is for documentation purposes and does not affect how Eloquent accesses the database column. When you use the model attribute in your code, you should always refer to it with the actual column name, even if it starts with a number.