1

I have a coloumn in my database named using camelCase convention how should i put it in the mutator naming to work ?

migration

 public function up() { Schema::create('skillTypes', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->boolean('needRating'); $table->timestamps(); }); } 

I named it like that but didnt work and also named it setNeedRatingAttribute and didnt work either

the mutator

 public function setneedRatingAttribute($input){ if($input==null){ $input=false; } else{ $input=true; } $this->attributes['needRating']=$input; } 

2 Answers 2

1

Add this property to your Model

public static $snakeAttributes = false; 

and rename method from setneedRatingAttribute to setNeedRatingAttribute

Sign up to request clarification or add additional context in comments.

Comments

0

First of all, the mutator you provided works. You could rename it to setNeedRatingAttribute for readability.

Secondly, you can replace the if in your setter with:

$this->attributes['needRating'] = boolvar($input); 

3 Comments

in postgresql if I dont set it it consider it null so i have to set it to false and i used dd($input) to check if it work but it is never entered
In case of not null collumns it might happen - but you can just do $this->attributes['needRating'] = boolvar($input); and skip the if. I updated the answer. Anyway, the setter should work
solved it the reason was it was never sent from the form so it never entered the mutator and I thought the problem was in the naming sorry for the inconvenience thought thanks for your help

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.