简体   繁体   English

Laravel 5.2模型绑定属性模糊

[英]Laravel 5.2 model binding attribute obfuscate

I am using Form::model to creates form for a model with Laravel 5.2. 我正在使用Form::model model使用Laravel 5.2为模型创建表单。 In the documentation they wrote: 他们在文档中写道:

When you generate a form element, like a text input, the model's value matching the field's name will automatically be set as the field value. 当您生成表单元素(例如文本输入)时,与字段名称匹配的模型值将自动设置为字段值。 So, for example, for a text input named email , the user model's email attribute would be set as the value 因此,例如,对于名为email的文本输入,将用户模型的email属性设置为值

But in that way, all the model fields name will be public. 但是通过这种方式,所有模型字段名称都将是公共的。 So the client will be able to see the exactly name of the fields of my internal program (even in the database), and I want to prevent that. 因此,客户端将能够看到内部程序(甚至在数据库中)的字段的确切名称,而我想避免这种情况。 In the internal code, I want to use the real field's name, but to hide them from the client. 在内部代码中,我想使用真实字段的名称,但要对客户端隐藏它们。

Is there any way to still using model binding but obfuscate the fields name? 有什么办法仍然可以使用模型绑定,但是会混淆字段名称?

You could create dynamic attributes on the model using the 您可以使用来在模型上创建动态属性

protected $appends = ['foo'];

property. 属性。 Then you can access these attributes via the following convention: 然后,您可以通过以下约定访问这些属性:

 public function getFooAttribute() {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM