Laravel Model relationship "Page have many Attachments"

  eloquent--relationship, laravel, php

I have models:


  • id
  • slug


  • id
  • file


  • id
  • file

I need the Page model to have a relation with several Image and Video models through one relationship, like

foreach($page->attachments as $attachment)
    // $attachment can be Image or Video

And inserts like

$attachments = [$image, $video];

I tried to make a morph relationship, but nothing comes of it, please help.

Source: Laravel

Leave a Reply