-
app/Models/Group.php
Open in GitHubuse Illuminate\Database\Eloquent\Relations\MorphToMany; class Group extends Model { // public function links(): MorphToMany { return $this->morphedByMany(Link::class, 'groupable'); } // }
-
app/Models/Link.php
Open in GitHubuse Illuminate\Database\Eloquent\Relations\MorphToMany; class Link extends Model { // public function groups(): MorphToMany { return $this->morphToMany(Group::class, 'groupable'); } // }
-
app/Http/Controllers/LinkController.php
Open in GitHubclass LinkController extends Controller { // public function store(StoreLinkRequest $request): RedirectResponse { // $groupIds = $validated['groups']; $link->groups()->sync($groupIds); // return Redirect::route('links.show', $link->id); } // }