Eloquent 中的保留列名 [英] Reserved column names in Eloquent

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

问题描述

粗略查看 IlluminateDatabaseEloquentModel 我可以看到以下实例属性:

From a cursory look into IlluminateDatabaseEloquentModel 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

问题:

  • 为什么这些东西不是 static,因为它们是类级配置的东西?
  • 这是否意味着我不能将这些名称用于我的表列?
  • 是否有不能用作表格列的正式名称列表?
  • 如果我有一个包含这样命名的列的旧表怎么办?
  • 这个天才想法是谁想出的?
  • 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?

推荐答案

这些属性不能是静态的,因为它们被用作它们的模型配置.如果你在你的模型类中重写它们,你定义自己的参数,如果不是,Eloquent 认为它应该使用默认值.是的,您的表中不应有与这些属性之一的名称匹配的列名称.

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.

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

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