Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Automatically generate interactive entity relationship diagram for models & thei

This package is a heavily-customized fork from [kevincobain2000/laravel-erd](https://github.com/kevincobain2000/laravel-erd) meant for use in some very specific circumstances. If you're not part of @NIT-Administrative-Systems, you should probably check out the original package instead!

The changes include:

- Adding ribbons to models in the diagram with PHP attributes on the model class
- Different default settings for goJS to render huge diagrams efficiently
- Different default settings for discovering models in `App\Domains\<something>\Models` namespaces

## Installation
You can install the package via composer.

Expand All @@ -18,3 +24,66 @@ php artisan erd:generate
```

This will be placed in `docs/.vuepress/public/erd`, or whatever path you have configured in `config/laravel-erd.php`.

## Using Ribbons
Enabling ribbon support is done by registering a function to get ribbons.

First, create an attribute with some properties you want to include in the ribbon:

```php
#[Attribute(Attribute::TARGET_CLASS)]
class LookupAttr
{
public function __construct(
public readonly string $source,
) {
//
}
}
```

Next, register a callback in a provider's

```php
class AppServiceProvider extends ServiceProvider {
public function boot(): void
{
/** @var ModelRibbonAdapter $adapter */
$adapter = resolve(ModelRibbonAdapter::class);

\Kevincobain2000\LaravelERD\LaravelERDServiceProvider::setRibbonClosure($adapter->callback());
}

private function ribbonCallback(): Closure
{
return function (Model $model) {
$reflection = new ReflectionClass($model);
$attributes = collect($reflection->getAttributes())
->map->newInstance()
->filter(fn (object $attrObj) => $attrObj instanceof LookupAttr);

return $attributes
->map(function (LookupAttr $attr) {
return new \Kevincobain2000\LaravelERD\Diagram\Ribbon(
text: $attribute->source,
bgColour: '#FFE342',
textColour: 'black',
);
})
->first();
};
}
}
```

And then use the attribute on some models:

```php
#[LookupAttr('Student System')]
class DegreeType extends Model
{
// . . .
}
```

This will pick them up and add a ribbon with the "Student System" text on it, indicating the table is populated from the student system's degree types.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"require-dev": {
"brianium/paratest": "^7.0",
"laravel/pint": "^1.10",
"nunomaduro/collision": "^7.0",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^10.0"
"nunomaduro/collision": "^8.0",
"larastan/larastan": "^3.1",
"orchestra/testbench": "^10.0",
"phpunit/phpunit": "^11.0"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- vendor/larastan/larastan/extension.neon
- vendor/nesbot/carbon/extension.neon

parameters:

Expand Down
9 changes: 8 additions & 1 deletion src/Commands/LaravelERDCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ public function handle(LaravelERD $modelReflector): int
File::makeDirectory($this->destinationPath, 0755, true);
}

/**
* I think the package erd:: prefix is confusing it; it doesn't see this as a view-string.
*
* @var view-string $view
*/
$view = 'erd::index';

File::put($this->destinationPath.'/index.html',
view('erd::index')
view($view)
->with([
'appName' => $this->appName,
'routingType' => $this->routingType->value,
Expand Down
Loading