PHP code example of northwestern-sysdev / er-diagram-tool
1. Go to this page and download the library: Download northwestern-sysdev/er-diagram-tool library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
northwestern-sysdev / er-diagram-tool example snippets
php artisan erd:generate
#[Attribute(Attribute::TARGET_CLASS)]
class LookupAttr
{
public function __construct(
public readonly string $source,
) {
//
}
}
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();
};
}
}
#[LookupAttr('Student System')]
class DegreeType extends Model
{
// . . .
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.