Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Not Clearing With morphTo/morphedByMany #431

Open
reasecret opened this issue Jun 23, 2022 · 0 comments
Open

Cache Not Clearing With morphTo/morphedByMany #431

reasecret opened this issue Jun 23, 2022 · 0 comments

Comments

@reasecret
Copy link

reasecret commented Jun 23, 2022

I have Project, Service, User and Bookmark models. A user can bookmark a project, a service or another user.

Project, Service, Bookmark and User models are cachable.

User model:

public function bookmarkedProjects()
	{
		return $this->morphedByMany(Project::class, 'bookmarkable', 'bookmarks');
	}

public function bookmarkedUsers()
	{
		return $this->morphedByMany(User::class, 'bookmarkable', 'bookmarks');
	}

public function bookmarkedServices()
	{
		return $this->morphedByMany(Service::class, 'bookmarkable', 'bookmarks');
	}

Bookmark model:

public function bookmarkable()
	{
		return $this->morphTo();
	}

The problem is, when user deleted a bookmark, database record deleting but cache not flushing and there is no error. I have to use modelCache:clear. And if I remove Cachable from models there is no problem.

Delete function (Other functions are same. Except bookmarkable_type):

public function removeBookmarkedService(string $id)
	{
		Bookmark::where('bookmarkable_type', 'App\Models\Service')->where('user_id', Auth::user()->id)->where('bookmarkable_id', $id)->delete();

		$this->emit('refreshPage');
	}

Environment

  • PHP: [8.1.3]
  • OS: [Windows 10]
  • Laravel: [9.18]
  • Model Caching: [0.12.4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant