Php Laravel 5 camelCase突变子命名
我的数据库中有一个名为usingcamelcase约定的column,我应该如何将它放入mutator命名中才能工作 迁移Php Laravel 5 camelCase突变子命名,php,model,laravel-5,eloquent,Php,Model,Laravel 5,Eloquent,我的数据库中有一个名为usingcamelcase约定的column,我应该如何将它放入mutator命名中才能工作 迁移 public function up() { Schema::create('skillTypes', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->boolean
public function up()
{
Schema::create('skillTypes', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->boolean('needRating');
$table->timestamps();
});
}
我这样命名它,但不起作用,还将它命名为setNeedRatingAttribute,但也不起作用
突变子
public function setneedRatingAttribute($input){
if($input==null){
$input=false;
}
else{
$input=true;
}
$this->attributes['needRating']=$input;
}
首先,你提供的变异因子是有效的。为了便于阅读,您可以将其重命名为setNeedRatingAttribute 其次,您可以将setter中的if替换为:
$this->attributes['needRating'] = boolvar($input);
将此属性添加到模型中
public static $snakeAttributes = false;
在PostgreSQL中重命名方法>代码> > StnEndRATIGATION < /COD> < /P>如果我不设置它,它认为它是NULL,所以我必须将它设置为false,并且我使用DD($输入)来检查它是否工作,但是它在没有空的COLUMN的情况下不可能发生它可能发生的情况,但是您可以只做$->属性[NeDrutt]。=布尔瓦尔(输入);跳过if。我更新了答案。无论如何,setter应该解决它,原因是它从未从表单中发送,因此它从未进入mutator,我认为问题在于命名抱歉给您带来不便,谢谢您的帮助