Download the PHP package moneo/laravel-morphmap without Composer

On this page you can find all versions of the php package moneo/laravel-morphmap. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-morphmap

Laravel Custom Morph Map

Tests Latest Stable Version License

Use different morph maps for different relationships on the same model.

By default, Laravel's Relation::morphMap() applies globally to all polymorphic relationships. This package lets you define a custom morph map per relationship, so different polymorphic relations on the same model can use different type aliases.

Requirements

Version PHP Laravel
2.x ^8.1 10, 11, 12
1.x >=8.0 8, 9, 10, 11

Installation

No service provider registration is needed. Just use the trait.

Usage

Add the HasCustomMorphMap trait to your model and define the $customMorphMap property in your constructor.

The array keys are the related model's fully qualified class name, and the values are the morph type alias you want stored in the database for that relationship:

Inverse Relationships (morphedByMany)

The trait also supports morphedByMany for inverse polymorphic many-to-many relationships:

How It Works

The trait uses Laravel's initializeHasCustomMorphMap() convention to automatically set the default morph type when the model is constructed. No need to call parent::__construct() before setting properties -- the trait handles initialization automatically.

When you call morphToMany() or morphedByMany(), the trait:

  1. Looks up the related model class in your $customMorphMap array
  2. If found, registers that alias in Laravel's global morph map
  3. If not found, uses the $defaultMorphType (which defaults to the model's FQCN)
  4. Delegates to the parent relationship method

Example Scenario

Suppose your taggables table uses fully qualified class names, but your categoryables table uses short aliases:

taggables

tag_id taggable_id taggable_type
1 1 App\Models\Post
2 1 App\Models\Video

categoryables

category_id categoryable_id categoryable_type
1 1 post
2 1 video

With this package, both table structures work seamlessly on the same model.

Testing

Static Analysis

Code Style

Contributing

Contributions are always welcome! Please see CONTRIBUTING.md for details.

Thanks to all of our contributors!

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-morphmap with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/database Version ^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package moneo/laravel-morphmap contains the following files

Loading the files please wait ...