Download the PHP package spatie/laravel-morph-map-generator without Composer

On this page you can find all versions of the php package spatie/laravel-morph-map-generator. 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-morph-map-generator

Automatically generate morph maps in your Laravel application

Latest Version on Packagist Tests Psalm Check & fix styling Total Downloads

With this package, you shouldn't worry about forgetting to add models to your application's morph map. Each model will autoregister itself in the morph map. The only thing you should do is implementing the getMorphClass method on your models like this:

From now on, the Post model will be represented as post within your morph map.

Support us

We invest many resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

You can publish the config file with:

This is the contents of the published config file:

Usage

First, you have to implement getMorphClass for the models you want to include in your morph map. We suggest you create a new base model class in your application from which all your models extend. So you could throw an exception when getMorphClass was not yet implemented:

When a model is not implementing getMorphClass, it will throw an exception when building the generated morph map, making it possible to quickly find models that do not have a morph map entry.

When autogenerate is enabled in the morph-map-generator config file, the morph map in your application will be dynamically generated each time the application boots. This is great in development environments since each time your application boots, the morph map is regenerated. For performance reasons, you should cache the dynamically generated morph map by running the following command:

Removing a cached morph map can be done by running:

When using Laravel 11+, the morph map can also be cached by using Laravel's optimize commands: optimize and optimize:clear

Using a custom resolver

You can also determine morph class values programmatically by using a custom resolver. For example, you could use the following to automatically derive the value based on the singular form of the model's table name:

Be warned! When the output of the closure above is not stable then you'll manually need to update all the morhp_type columns within your database. Using something like the table name is a good idea since those do not change that often.

You may set the resolver in the boot method of one of your service providers.

Models outside your path

Some models like the default Laravel User model and models defined by packages will not be discovered by this package since it only searches for models within the app path and not the complete vendor directory. You can include these models in your morph map by using the default morph map feature from Laravel:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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


All versions of laravel-morph-map-generator with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
ext-json Version *
illuminate/console Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/contracts Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/database Version ^8.0|^9.0|^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 spatie/laravel-morph-map-generator contains the following files

Loading the files please wait ....