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