Download the PHP package schenke-io/laravel-relation-manager without Composer

On this page you can find all versions of the php package schenke-io/laravel-relation-manager. 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-relation-manager

Version Downloads Tests License PHP

Schenke Io Laravel Relation Manager

Allow to plan, document and test model relations in Laravel

Developing complex Laravel applications with many models can be difficult. Laravel Relation Manager helps by bringing all your model relationships together. It creates tests to make sure they work and documents them for easy reference. This saves you time, improves code quality, and keeps your project organized.

Installation

You can install the package via composer:

After installation, you can start by scanning your models and generating the initial .relationships.json file:

Workflow

Laravel Relation Manager helps you maintain consistency in your Eloquent relationships through a simple three-step process:

  1. Extract: php artisan relation:extract - Scans your models and saves the relationship state to .relationships.json.
  2. Verify: php artisan relation:verify - Ensures your code implementation matches the defined relationship state.
  3. Draw: php artisan relation:draw [filename] - Generates visualization (diagrams and tables) of your model relationships.

The Draw Command

The relation:draw command generates a comprehensive Markdown file (default: RELATIONS.md) that includes:

You can optionally provide a filename to override the default path.

Understanding the Diagram

In the Mermaid diagram, arrows represent relationships between tables.

FAQ: Why is there an arrow from tags to regions? This occurs when a model (like Tag) has a relationship method pointing to another model (like Region). Even if the database foreign key is on a pivot table or the other model, the diagram reflects the intent of the relationship method defined in the model.

Suggestion: If you want to exclude certain methods from the diagram, use the #[Relation(EloquentRelation::noRelation)] attribute.

Configuration

The .relationships.json file contains a config section to customize the behavior:

Examples and Guides

This guide provides practical examples of how to use the Laravel Relation Manager with its new features.

1. Automatic Discovery

The easiest way to get started is by letting the package discover your relations automatically. Ensure your model methods have proper return type hints.

When you run php artisan relation:extract, this relation will be automatically detected and saved to .relationships.json.

2. Declarative Relations via Attributes

Sometimes you might want to provide additional metadata to your relationships or explicitly mark methods to be ignored.

On the Method Level

Automatic Reverse Relations

You can tell the scanner to automatically inject the inverse relation into the related model:

Suppressing Relationships

If you have a method that should not be treated as a relationship, you can explicitly mark it with noRelation:

3. Testing Your Relations

Using PHPUnit

Add the RelationTestTrait trait to your test class:

Using Pest

If you are using Pest, you can use the fluent expectations:

4. Visualizing Relations

Generate a diagram or a Markdown table of your relations:

By default, this command uses the data from .relationships.json. It supports:

Mermaid Diagram Example

Relationship Table Example

ModelMethod(): RelationRelated ModelReverse Relation
Userposts(): hasManyPostPost::author
profile(): hasOneProfileProfile::user

Here an example of a generated markdown file.

Testing Relationships

The package provides built-in tools to verify that your model implementation matches your .relationships.json file. This ensures that your documentation, diagrams, and actual code are always in sync.

Strict vs. Loose Mode


PHPUnit Integration

To use with PHPUnit, create a test class that extends AbstractRelationTest.

The base class provides the following tests:

  1. test_laravel_environment: Ensures the test runs within a Laravel environment.
  2. test_relationship_json_exists_and_is_valid: Verifies that the JSON file is present and correctly formatted.
  3. test_models_match_json_state: Compares the model implementation against the JSON definition.

Pest PHP Integration

For Pest, you can use the RelationTestBridge to quickly register all necessary tests in a single call.

This will automatically register three tests in your Pest file:

  1. test('laravel environment', ...)
  2. test('relationship json exists and is valid', ...)
  3. test('models match json state', ...)

Markdown file generated by schenke-io/packaging-tools


All versions of laravel-relation-manager with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
illuminate/contracts Version ^12.0 || ^13.0
spatie/laravel-data Version ^4.18
spatie/laravel-package-tools Version ^1.90
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 schenke-io/laravel-relation-manager contains the following files

Loading the files please wait ...