1

I'm a newbie in spatie. I have some trouble, I don't know how to change collection_name in spatie.

I select a record with collection_name is enter code here and change it to doctor_avatar and I do like:

$media = Media::where(['model_id' => $id, 'collection_name' => 'log_doctor_avatar'])->get();
$media->update([
'collection_name' => 'doctor_avatar',
]);

But have an error: BadMethodCallException Method update does not exist.

Can you help me solve this problem!

apokryfos
  • 38,771
  • 9
  • 70
  • 114
Ngoc Tran
  • 69
  • 2
  • 12
  • Do you want to change a collection name or do you want to move media from one collection to a different one? – brombeer Jan 18 '19 at 08:27
  • I want to change collection name and did it. But how can i move media from one collection to a different one? Can you help me? – Ngoc Tran Jan 18 '19 at 09:54

1 Answers1

1

Problem is, that your variable $media is type Collection, and Collection does not have update method (as you can see in error message).

Try it like this:

$media = Media::where(['model_id' => $id, 'collection_name' => 'log_doctor_avatar'])->update(['collection_name' => 'doctor_avatar',]);
Autista_z
  • 2,491
  • 15
  • 25