Skip to content

A short example of how to use Laravel Many to Many Polymorphic Relationships with pivot data on the relation table.

Notifications You must be signed in to change notification settings

ricardov03/polyrelations

Repository files navigation

Build Status Total Downloads Latest Stable Version License

Explaining Many To Many Polymorphic Relationship

This repository has the main purpose to respond to the following asked question from Stack Overflow: https://stackoverflow.com/questions/68073778/laravel-polymorphic-many-to-many-relationship-pivot-table-with-relationship-to-a?noredirect=1#comment120387610_68073778

The Problem

  • The user needs to establish a relation between tree models using Polymorphic relations to attach resources and avoid duplication.
  • The user wants to add some custom fields to the relation table and load this content when retrieving the assets.

The Answer

  • Check the README.md file on the Controllers folder.

How to use this Repository

  • Clone the project.
  • Configure a Database. I already included a Sqlite3 DB on the project. Just update the drive to sqlite and set the DB_DATABASE variable to your /project/route/path/./database/relations.db
  • Migrate the Database.
    php artisan migrate:fresh --seed
    # I use the seed flag to include some samples in the database.
  • Review the Migrations
  • Review the Models
  • Check the Action Controller to understand how to retrieve and store information using Eloquent.

About

A short example of how to use Laravel Many to Many Polymorphic Relationships with pivot data on the relation table.

Topics

Resources

Stars

Watchers

Forks