Download the PHP package kaveh/morph-service without Composer
On this page you can find all versions of the php package kaveh/morph-service. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package morph-service
Laravel Morph Service 📦
Overview
The Laravel Morph Service package simplifies adding media files to multiple models without the need for separate media tables for each model. Instead, it provides a unified media table that associates files with different models dynamically.
This is achieved using mediable_id and mediable_type, which store the ID and type of the model that owns the media file. For example, if you want to store a profile picture for a User, the table will store the user_id as mediable_id and User as mediable_type. This structure makes it easy to retrieve media files related to specific models while maintaining a clean and structured database design.
🔧 Installation
To install the package, run the following command:
Then, add the provider in bootstrap/provider.php:
To ensure the package integrates properly with your project, add the following to composer.json:
Then, run:
📌 Database Migration
Run the migration command to set up the required tables:
📂 Usage
1️⃣ Define the Media Relationship
For any model that needs to support media files, add the following method:
2️⃣ Upload Media in Your Controller
To upload a file and associate it with a model, use the following:
🎯 Benefits
✔ Single media table for all models – No need for separate media tables.
✔ Flexible association – Easily attach media to different models dynamically.
✔ Efficient querying – Retrieve media files related to any model without extra joins.
This package streamlines media management in Laravel, making file storage more efficient and scalable! 🚀