保持列名称在雄辩 [英] Reserved column names in Eloquent

查看:130
本文介绍了保持列名称在雄辩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b $我可以看到以下实例属性:

  protected $ connection 
protected $ table
protected $ primaryKey
protected $ perPage
public $ incrementing
public $时间戳
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

问题:




  • 为什么这些东西不是 static ,看到他们是类级别配置东西?

  • 这是否意味着我不能在表列中使用这些名称?


  • 如果我有一个名为这样的列的遗留表,该怎么办?

  • 谁想出了这个天才的想法?


解决方案

这些属性不能是静态的,因为他们被用作他们的模型配置。如果您在模型类中重写它们,那么您可以定义自己的参数,如果没有,那么这个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?

解决方案

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.

这篇关于保持列名称在雄辩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆