diff --git a/app/Models/MediaModel.php b/app/Models/MediaModel.php index bc61689d23e6b749587d88381194907f04bc0a4f..b3900618a30c548f8684cb541568b2246d4d9359 100644 --- a/app/Models/MediaModel.php +++ b/app/Models/MediaModel.php @@ -65,6 +65,18 @@ class MediaModel extends Model 'updated_by', ]; + /** + * clear cache before update if by any chance, the podcast name changes, so will the podcast link + * + * @var string[] + */ + protected $beforeUpdate = ['clearCache']; + + /** + * @var string[] + */ + protected $beforeDelete = ['clearCache']; + /** * Model constructor. * @@ -166,4 +178,19 @@ class MediaModel extends Model return $this->delete($media->id, true); } + + /** + * @param mixed[] $data + * + * @return mixed[] + */ + protected function clearCache(array $data): array + { + $mediaId = (is_array($data['id']) ? $data['id'][0] : $data['id']); + + cache() + ->delete("media#{$mediaId}"); + + return $data; + } } diff --git a/modules/Admin/Controllers/PodcastController.php b/modules/Admin/Controllers/PodcastController.php index cf56486020f89c8fef7f5850b64abfacd86072cd..8cbbcb96c9a171acb3429bae245e9cc6603e6021 100644 --- a/modules/Admin/Controllers/PodcastController.php +++ b/modules/Admin/Controllers/PodcastController.php @@ -381,6 +381,9 @@ class PodcastController extends BaseController ->withInput() ->with('errors', $mediaModel->errors()); } + (new PodcastModel())->clearCache([ + 'id' => $this->podcast->id, + ]); // remove banner url from actor $actor = (new ActorModel())->getActorById($this->podcast->actor_id);