Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cache Not Clearing With morphTo/morphedByMany #497

reasecret started this conversation in General
Discussion options

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]
You must be logged in to vote

Replies: 2 comments

Comment options

Are there any other workarounds on this issue? aside from clearing model cache?

You must be logged in to vote
0 replies
Comment options

@reasecret Thanks for reporting this.
@bcaballero I believe this might be due to the MorphToMany relationship -- it probably isn't enforced in caching.

It would really help if you could contribute a PR with a failing test, or even with the complete solution.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Converted from issue

This discussion was converted from issue #431 on March 05, 2025 13:53.

AltStyle によって変換されたページ (->オリジナル) /