Skip to content
Advertisement

How to change collection_name in spatie?

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!

Advertisement

Answer

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',]);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement