Examples of Polymorphic relationships (6)

Short information about polymorphic relationships

Polymorphic relationships are used when there may be multiple models related to one particular model, with the potential to have even more models in the future.
For example, Tags may be related to Articles, or to Photos, or maybe in the future to Users, or to Comments, etc. So, to avoid changing the database structure for those new models, you define a Polymorphic relationship, and re-use it for all current/future models, just by changing the Model classes code, but not the database itself.
Read more in the official Laravel docs.

Repository: laravelio/laravel.io (Github)
★ 1889 Created: May 2016 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Models/Tag.php
- app/Helpers/HasTags.php
- app/Models/Thread.php
- app/Helpers/HasLikes.php
- app/Models/Article.php
- app/Jobs/CreateArticle.php
- app/Jobs/LikeArticle.php
Repository: guillaumebriday/laravel-blog (Github)
★ 1317 Created: Dec 2016 Updated: May 2021 Laravel version: 8
Files in the example:
- database/migrations/2017_11_15_003340_create_likes_table.php
- app/Models/Like.php
- app/Models/Post.php
- app/Concern/Likeable.php
- app/Http/Controllers/Api/V1/PostLikeController.php
Repository: tighten/onramp (Github)
★ 129 Created: Jul 2019 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Models/Module.php
- app/Models/User.php
- app/Models/Completion.php
Repository: serversideup/financial-freedom (Github)
★ 88 Created: Mar 2021 Updated: Oct 2021 Laravel version: 8
Files in the example:
- app/Models/Transactions/Transaction.php
- app/Services/Transactions/AddTransaction.php
Repository: academico-sis/academico (Github)
★ 45 Created: Dec 2018 Updated: Aug 2021 Laravel version: 8
Files in the example:
- database/migrations/2018_12_20_142237_create_comments_table.php
- app/Models/Comment.php
- app/Http/Controllers/CommentController.php
- resources/views/students/show.blade.php
- resources/js/components/StudentCommentComponent.vue
- app/Models/Student.php
Repository: JuanDMeGon/Laravel-from-Scratch (Github)
★ 11 Created: Apr 2020 Updated: Mar 2021 Laravel version: 8
Files in the example:
- app/Cart.php
- app/Product.php
- app/Http/Controllers/OrderController.php

Additional resources on polymorphic relationships: