0

I am trying to add a new item to my object but I get an error:

Here is my code:

$q = Question::where('id',$id -> id)->first();
$q[]=$q->push('test',5);
dd($q);

Here is what this return:

Missing argument 2 for Illuminate\Database\Eloquent\Model::setAttribute(), called in /home/client/public_html/storage/framework/compiled.php on line 10231 and defined

Any idea how to fix this?

CrackingTheCode
  • 802
  • 1
  • 11
  • 26
Vladimir Djukic
  • 2,042
  • 7
  • 29
  • 60

1 Answers1

0

According to Laravel doc,

Sometimes you may wish to save not only a model, but also all of its relationships. To do so, you may use the push method

Therefore push() will try to presist the attribute and it will fail because it doen't exist in your model table. Instead of using push(), use dynamic attributes:

$q->randomAttribute = "value";

I am not sure how you are planning to use this attribute later, maybe then I can give you a better answer.

CrackingTheCode
  • 802
  • 1
  • 11
  • 26