Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reserved column names in Eloquent

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?
like image 432
Tobia Avatar asked May 23 '16 17:05

Tobia


2 Answers

It appears that $changes is also a reserved name.

like image 187
Alaa Shaheen Avatar answered Oct 18 '22 23:10

Alaa Shaheen


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.

like image 20
Walter Gandarella Avatar answered Oct 18 '22 23:10

Walter Gandarella