问题
From a cursory look into Illuminate\Database\Eloquent\Model
I can see the following instance attributes:
protected $connection
protected $table
protected $primaryKey
protected $perPage
public $incrementing
public $timestamps
protected $attributes
protected $original
protected $relations
protected $hidden
protected $visible
protected $appends
protected $fillable
protected $guarded
protected $dates
protected $dateFormat
protected $casts
protected $touches
protected $observables
protected $with
protected $morphClass
public $exists
public $wasRecentlyCreated
Questions:
- Why are these things not
static
, seeing as they are class-level configuration stuff? - Does it mean I cannot use these names for my table columns?
- Is there an official list of names one cannot use as table columns?
- What if I have a legacy table with columns named like this?
- Who came up with this genius idea?
回答1:
These attributes can not be static because they are used as their model configuration. If you rewrites them in your model class, you define your own parameters, if not, the Eloquent believes it should use the defaults. Yes, you should not have a column name in your table that matches the name of one of these attributes.
回答2:
It appears that $changes
is also a reserved name.
来源:https://stackoverflow.com/questions/37396741/reserved-column-names-in-eloquent