Detach on eloquent collection not working

Solution for Detach on eloquent collection not working
is Given Below:

In a Post model I have:

public function tags()
{
  return $this->morphToMany(AppModelsTag::class, 'taggable');
}

But when I then do:

$posts = Post::all();
$posts->tags()->detach();

I get

Method IlluminateDatabaseEloquentCollection::inputs does not exist.

Based on your code, it seems like you’re trying to remove all the tags from all the existing posts in your application.

If this is what you’re trying to do, then follow @A.A Noman comment: you should detach them by iterating the collection, one by one.
Another option is to just clear the intermediate table containing the relations.

If what you’re trying to do here is detaching all the tags from a single Post, you can search the post and then detach all the tags:

$post = Post::find($id);
$post->tags()->detach();

UPDATE

To iterate the collection and remove all the Tags from all the Posts:

$posts = Post::all();

foreach ($posts as $post) {
    $post->tags()->detach();
}

Use Laravel’s with()

https://laravel.com/docs/8.x/eloquent-relationships

To bring the tags related to this collection

Example:

$posts = Post::with('tags');
$posts->tags()->detach();

Likewise, if you want to remove a particular entity relationship from the pivot table, you can use the detach method.

For example, if you want to remove a certain author from a book, you can do so.

$book->authors()->detach($authorId);

Or you can pass multiple IDs as an array.

$book->authors()->detach([4, 5, 8]);

Or, if you want to remove all authors from a book, use detach without passing any arguments.

$book->authors()->detach();