Download the PHP package sebastiaanluca/laravel-auto-morph-map without Composer

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

Automatically alias and map the polymorphic types of Eloquent models

Latest stable release Build status Total downloads Total stars

Read my blog View my other packages and projects Follow @sebastiaanluca on Twitter Share this package on Twitter

Decouple your internal application namespace structure from your database by automatically aliasing and mapping your Eloquent models as short, uniform class names instead of full class namespaces.

By default, Laravel will use the fully qualified class name to store the type of the related model. For instance, given the example above where a Comment may belong to a Post or a Video, the default commentable_type would be either App\Post or App\Video, respectively. However, you may wish to decouple your database from your application's internal structure. In that case, you may define a relationship "morph map" to instruct Eloquent to use a custom name for each model instead of the class name.

See Custom Polymorphic Types in the Laravel documentation for more information.

Laravel auto morph map improves upon that by scanning all your Eloquent models, automatically aliasing them as uniform singular table names, and registering them as a polymorphic type. No more need for dozens of manual Relation::morphMap() calls to register model morph types and no need to maintain that pesky morph map list when you add, change, or remove a model.

Table of contents

Requirements

How to install

Via Composer:

How to use

After installing this package, you're immediately good to go! The package will scan all your models and automatically register their polymorphic types on-the-fly.

Besides scanning and aliasing your models for you, this package alters no native Laravel functionality. Therefore, see the Laravel documentation on how to use custom polymorphic types.

If you wish to customize some behavior, read further.

Defining model namespaces

Laravel auto morph map uses your composer.json PSR-4 autoload section to know which namespaces and paths to scan. In any new Laravel project, the default App\\ namespace is already in place, so for most projects no additional setup required. If you have other namespaces registered like local modules or (dev) packages, those will be scanned too.

Furthermore it filters out traits, abstract classes, helper files, and other unusable items to only bind valid Eloquent models.

Overriding existing aliases

If you wish, you can still override already aliased morph types in your service provider's boot method like you would normally:

These will always have priority over the already defined ones.

Caching morph types in production

To cache all aliases and speed up your application in production, add the cache command to your deploy scripts:

This scans all your current models and writes a static cache file to the bootstrap/cache directory. Upon subsequent framework booting, it reads the cache file instead of scanning and aliasing on-the-fly.

Note that this thus disables runtime scanning, meaning new models will not be recognized and changes to existing models will not be reflected (not very handy during development).

To clear the cache file, run:

Configuration

Run

and select

to publish the configuration file.

Naming

The naming scheme to use when determining the model's morph type base value. Defaults to the singular table name (automatically determined by Laravel or overridden in the model using the $table variable).

You can change this to use the singular table name, table name, or class basename. See \SebastiaanLuca\AutoMorphMap\Constants\NamingSchemes for possible options.

Singular table name (default):

Table name:

Class basename:

Casing

Converts your model name (after having passed the naming scheme conversion) to a more uniform string. By default, the model's name (based on your naming scheme) is converted to snake case.

You can change this to use snake, slug, camel, studly or no casing. See \SebastiaanLuca\AutoMorphMap\Constants\CaseTypes for possible options.

Snake case (default):

Slug case:

Camel case:

Studly case:

None (determined by your naming scheme and Laravel's class-to-table conversion method):

License

This package operates under the MIT License (MIT). Please see LICENSE for more information.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

Contributing

Please see CODE OF CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

About

My name is Sebastiaan and I'm a freelance back-end developer specializing in building custom Laravel applications. Check out my portfolio for more information, my blog for the latest tips and tricks, and my other packages to kick-start your next project.

Have a project that could use some guidance? Send me an e-mail at [email protected]!


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

PHP Build Version
Package Version
Requires php Version ^8.0
laravel/framework Version ^8.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 sebastiaanluca/laravel-auto-morph-map contains the following files

Loading the files please wait ....