Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

belykia's avatar

Call to a member function update() on array?? laravel 5.6

Hello Everybody: I am getting this error "Call to a member function update() on array" and I have no idea why, is it because I am updating an array? I have check other resources similar to this but not much related to array so I am not sure what to do. Thank you in advance

Controller: $post=Post::find($id); $post=$request->all(); $ASNumber = $request->input('asnumber'); $choice=$request->input('choices'); $peeringDB=$request->input('peeringdb'); $ASSET =$request->input('assets'); $Contact=$request->input('Contacts'); $post_data = [ 'asnumber' => $ASNumber, 'peeringrs' => $choice, 'peeringdb' => $peeringDB, 'asset' => $ASSET, 'contact' => $Contact ]; $post->update($post_data); return redirect('save');

0 likes
4 replies
tykus's avatar
$post=Post::find($id);
$post=$request->all();

You are assigning a Model to $post and then immediately overwriting that variable with the contents of the request (an array). Everything you have written could be condensed to:

$post=Post::find($id);

$post->update($request->all());

return redirect('save');
belykia's avatar

thank you for your answer @tykus , but i don t know why , it doesn't work , i think because i changed the name variables in the second form , i mean the edit.blade.php one . i want to make it with an array , so i did this solution , and doesn t work either :

$post=Post::find($id); $ASNumber = $request->input('asnumber'); $choice=$request->input('choices'); $peeringDB=$request->input('peeringdb'); $ASSET =$request->input('assets'); $Contact=$request->input('Contacts'); $post_data = [ 'asnumber' => $ASNumber, 'peeringrs' => $choice, 'peeringdb' => $peeringDB, 'asset' => $ASSET, 'contact' => $Contact ]; $post->update($post_data ); $post->save(); return redirect('save');

tykus's avatar
tykus
Best Answer
Level 104

So many temporary variables... again, we can tidy up your method:

$post=Post::find($id);

$post->update([
    'asnumber' => $request->input('asnumber'),
    'peeringrs' => $request->input('choices'),
    'peeringdb' => $request->input('peeringdb'),
    'asset' => $request->input('assets'),
    'contact' => $request->input('Contacts')
]);

return redirect('save');

update() persists the changes, so not need to save().

If it still is not working double-check that the database fields and fillable fields on your model are:

  • asnumber
  • peeringrs
  • peeringdb
  • asset
  • contact

Please or to participate in this conversation.