for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace Modelarium\Laravel\Directives;
use Illuminate\Support\Str;
use Modelarium\Laravel\Targets\ModelGenerator;
use Modelarium\Laravel\Targets\Interfaces\ModelDirectiveInterface;
class MigrationUniqueIndexDirective implements ModelDirectiveInterface
{
public static function processModelTypeDirective(
ModelGenerator $generator,
\GraphQL\Language\AST\Node $directive
): void {
}
public static function processModelFieldDirective(
\GraphQL\Type\Definition\FieldDefinition $field,
$fieldName = $field->name;
$studlyName = $generator->getStudlyName();
$generator->class->addMethod('from' . Str::studly($fieldName))
->setPublic()
->setStatic()
->setReturnType('\\App\\Models\\' . $studlyName)
->addComment("Factory from the $fieldName unique index")
->setBody("return {$studlyName}::firstWhere('$fieldName', \$value);")
->addParameter('value');
public function processModelRelationshipDirective(