-
composer.json
Open in GitHub{ "require": { "php": "^7.3", // "cviebrock/eloquent-taggable": "^8" }, }
-
app/Group.php
Open in GitHubuse Cviebrock\EloquentTaggable\Taggable; use Illuminate\Database\Eloquent\Model; class Group extends Model { use Taggable; }
-
app/Http/Controllers/GroupTagController.php
Open in GitHubclass GroupTagController extends Controller { public function edit(Request $request, Group $group, Tag $tag) { $discussion = new Discussion; $discussion->group()->associate($group); $tags = collect(); $discussions = $group->discussions() ->with('tags') ->get(); $files = $group->files() ->with('tags') ->get(); foreach ($discussions as $discussion) { foreach ($discussion->tags as $tag) { $tags->push($tag); } } foreach ($files as $file) { foreach ($file->tags as $tag) { $tags->push($tag); } } $tags = $tags->unique('normalized')->sortBy('normalized'); // } }